Question

ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive algorithms. We are ver
If n is 4, we have: foo(4), which is called once. This makes two calls to foo(3), which in turn makes 4 calls to foo(2), whic
1) Given the algorithm foo given above: a) Draw the recursion tree that shows the how many calls are generated for foo when n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

a)

foo(3) foo(2) foo(2) foo(1) foo(1) foo(1) foo(1)

b) Total calls made to foo is 4+2+1=7

c)

foo(4) foo(3) foo(3) foo(2) foo(2) foo(2) foo(2) foo(1) foo(1) foo(1) foo(1) foo(1) foo(1) foo(1) foo(1)

d) Total calls made to foo is 8+4+2+1=15

e) The approximate value of 15/7 is 2.

f) 2n+1

Add a comment
Know the answer?
Add Answer to:
ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Let’s work together to develop a call tree for the execution of the following recursive method....

    Let’s work together to develop a call tree for the execution of the following recursive method. (The method allows us to recursively generate the nth integer in the Fibonacci sequence, although you don’t need to be familiar with that sequence to understand this problem.) public static int fib(int n) { if (n == 0 || n == 1) { return 1; } else { int prev1 = fib(n - 2); int prev2 = fib(n - 1); return prev1 + prev2;...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • JAVA PROBLEM #1: The British have been shelling the Revolutionary forces with a large cannon from...

    JAVA PROBLEM #1: The British have been shelling the Revolutionary forces with a large cannon from within their camp. You have been assigned a dangerous reconnaissance mission -- to infiltrate the enemy camp and determine the amount of ammunition available for that cannon. Fortunately for you, the British (being relatively neat and orderly) have stacked the cannonballs into a single pyramid-shaped stack. At the top is a single cannonball resting on a square of 8 cannonballs, which is itself resting...

  • In this problem you will memoize your recursive solution to ladder() so that it will work...

    In this problem you will memoize your recursive solution to ladder() so that it will work for large numbers, i.e. long ladders. Do this by adding a Python dictionary called knownResults as the second parameter to ladder. It will store all results that have been previously computed. Always check knownResults before making a recursive call, and store results from recursive calls into knownResults. Your new definition line will look something like. def ladder(length, knownResults = {}): The calls to ladder...

  • Need assistance with small piece of larger assignment writing a recursive division algorithm (Java). The assignment is t...

    Need assistance with small piece of larger assignment writing a recursive division algorithm (Java). The assignment is to write a recursive division algorithm to build a maze in a 2D array. I have code that will randomly generate vertical and horizontal walls and randomly place doorways in the walls. Requirements: The maze should be broken into sub-regions on each recursive method call until the sub-region is no less than 3x3. My recursive calls only seem to work on the top...

  • Question 9 (1 point) Suppose the following foo function was called from when the current referencing...

    Question 9 (1 point) Suppose the following foo function was called from when the current referencing environment consisted only of the top level frame. If the function was called as shown below, how many reference frames will the referencing environment consist of once the base case is reached? Page 11 (define foo (lambda (n) (if (< n 1) -1 ; base case (let ((m (- n 1)) (if (even? n) (+ n (foo m)) (- n (foo m)) - )...

  • C++ Using Recursion We are going to create a (looping) menu that accesses functions that use...

    C++ Using Recursion We are going to create a (looping) menu that accesses functions that use recursion. The function headers and a description will be provided. You are responsible for defining the functions. Ensure that they each contain a base case they reach that doesn’t have a recursive function call, otherwise it’s an infinite loop! Functions must be implemented with recursion. int Factorial(int arg) Returns arg! (4! Is 4 * 3 * 2 = 24) Base case is Factorial(1) returning...

  • Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a...

    Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a single BIG integer (bigint) as its parameter n, and it will compute the factorial n! of the value and return it as its result (as a bigint). Write this functions using a loop (do not use recursion). 2. Write the factorial function again, but using recursion. Call this function factorialRecursive(). The function takes the same parameters and returns the same result as described in...

  • This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#)...

    This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#) and dots(.) is a 2D array representation of a maze # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . #...

  • What's wrong with my code? : I'm trying to use recursive functions to display and count...

    What's wrong with my code? : I'm trying to use recursive functions to display and count all the even numbers of an array. However, I can't seem get the program output the number of even integers . Here's the output I want: Here are the 5 even numbers: // Luckily, however, my code does output all the even numbers. But, I also want the program to tell me how may even integers there are. 2 8 14 18 22 MY...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT