Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

please explain your solution and explain every part of it. i do not understand how to reduce the number of elements by 2 or how to find the base case. please give a detailed answer for my understanding.

* Is the reccurence relationship 2n-1 or n-2? how did you get the recurrence relationship?

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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions