Question: Consider the following algorithm: ALGORITHM S(n)//Input: A positive integer n//output: The sum of the first n cubes if (n 1) return 1 else return S
Consider the following algorithm: ALGORITHM S(n)//Input: A positive integer n//output: The sum of the first n cubes if (n 1) return 1 else return S (n-1) + n*n*n a. Set up a recurrence relation, M(n), for the number of multiplications made by the algorithm. b. Solve the recurrence relation using Substitution (Iteration) method Assume M(1) = 0. c. Write a non-recursive, straightforward algorithm for computing the above algorithm. d. Compare the number of multiplication performed by the non-recursive algorithm with the recursive algorithm. Explain your observation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
