Modify the algorithm so that, with each iteration, the algorithm reduces the number of elements by 2
Fantastic news! We've Found the answer you've been seeking!
Question:
Modify the algorithm so that, with each iteration, the algorithm reduces the number of elements by 2 elements, provided there are more than 2 elements in the array. To compute the complexity of your algorithm, find the recurrence relationship for the algorithm (using worst case scenario) and solve it using forward or backward substitution.
Algorithm LinearRecSum( A, i, n ):
Input: An array A, an int i (starting index for the array) and n (# of elements)
Output: The sum of the n integers in A starting at index i
if n = 1 then
return A [ i ]
else
return A[i]+ LinearRecSum( A, i+1, n-1 )
Related Book For
Statistics for Management and Economics Abbreviated
ISBN: 978-1285869643
10th Edition
Authors: Gerald Keller
Posted Date: