Discrete Mathematics:
Assume you have a list of numbers, A, and A[i] represents the ith element of the list. Now please define a recursive function, f(n), which represents the sum of the first n elements in the list for n>=0.
Hint 1: a recursive function needs defining its initial value and the relationship between neighbors.
Hint 2: f(n) = A[1] + A[2] + A[3] + … + A[n-1] + A[n] is not what I am asking here.)
Base case:
f(0) = 0 //because no elements will be added n = 0
Recursive relation:
f(n) = f(n-1) + A(n)
Ex: suppose A[1] = 5, from above relation we have to get f(1) = 5. Let's see
f(n) = f(n-1) + A[n]
f(1) = f(0) + A[1]
= 0 + 5 {f(0) = 0 // base case}
= 5
similarly we can see for n = 2,3....
Note: If you have any doubts please comment.
It will be great help If you like.
Discrete Mathematics: Assume you have a list of numbers, A, and A[i] represents the ith element...
F# ONLY SOMEONE SOLVED IN PYTHON JUST NOW. I NEED F SHARP PROGRAMMING THANKS A more efficient version of the function for computing Tetranacci numbers can be defined by following three steps: Implement a function which takes a list of integers and adds the sum of the top four elements to the head of the list (e.g., in F#, 1::1::1::1::[] should become 4::1::1::1::1::[]). Implement a recursive function which accepts an integer n as input (again, assume n >= 0), and...
This is from discrete math. Please write clearly so I can understand. 3. Recall the Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, .... These are formed by defining the first two numbers, followed by a recursive formula for the rest: Fi = 1 and F2 = 1, where F = F.-2+ FR-2, where n EN and n 3. Let ne N and F. be the nth Fibonacci number. Prove that (6) +(";")+(";2)+(";") +--+ () =...
Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...
3.6.x10 every other We are passing in 3 inputs A list of numbers A multiplier value, M A value, N You should multiply every Nth element ( do not multiply the 0th element)by M. So if N is 3 you start with the 3rd element which is index 2 If there are less than N elements then you should output the unchanged input list Get our input from the command line port sys İnt(sys.argv [2] ) int (sys.argv[3]) Collape) Challengs...
This is discrete mathematics. I need answer and explanation for #28 #29 #30. Thank you so much!! 28. Define an "onto" function. Give an example of an onto function from X = {1,2,3,4,5,6,7,8,9,0} onto Y = {a,b,c,d} 29. What is the domain and co-domain of the function which assigns to each pair of non- negative integers the first integer of the pair? What is the range? 30. Let S be the set of all positive integers not exceeding 100. Let...
Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements. Example: >>>lst = [4, 1, 2, -1] >>>fun3(list) -8 >>>lst [-1, 1, 2, 4] *We are an intro to CS class so please do not use anything too advance or fancy. Stick to basics. Right...
2. Here is a sorting algorithm that I like to use. Given an unsorted list of size n, let Xx represent the data in location k of the unsorted list. Compare xi to X2 and switch if necessary so that they are in sorted order, smallest first. Compare Xn-1 and Xn and switch if necessary so that they are in sorted order, smallest first. • Compare x3 with its left neighbors, switching if necessary so that the 3 first entries...
An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and 1≤j<l≤n , we have >A[i,j]+a[k,l]≤A[i,l]+A[k,j]> In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following...
Using Mathematica, how do you type #1 and #2 in mathematica. exlist[ (2]1 exlist[(7]1 exlistit Length(exList] 1 Note that the last command gives us the last element of the list. We can also use extist[l-1]] for this. Negative numbers count backwards from the end of the list: exlist-1] exlisti-2]1 exListlI-3]1 1. Write a command accessing individual list elements to find the sum of the second and fifth element of our list exList. Summing Over a List Another important tool for...
Learning Objective Assessment: C6 (version 2) MATH2603: Discrete Mathematics C6: I can compute conditional probabilities, and probabilities for unions, comple- ments, or independent events. Two fair dice are thrown, one blue and one red. The events E, F, and G are defined as follows E: The sum on the two dice is less than or equal to 4. F: The sum on the two dice is even. G: Both dice come up 4. H: The red die comes up 1....