Question: Consider the following algorithm: Algorithm Foo (int a[], int n): Input : an array of integers a , and n is the length of the

Consider the following algorithm:

  • AlgorithmFoo(int a[], int n):

  • Input: an array of integersa, andnis the length of the array

  • Output: ?

  • If n<0 then show out of bound exception.

  • If n == 0 then

    • Return a[n];

  • Else

    • Return (a[n] * Foo(a, n-1))

What does this algorithm do? Analyze its worst-case running time, and express it using "Big O" notation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!