Question

Write down the run time of the following recursive functions as a recurrence relation: int f(...

Write down the run time of the following recursive functions as a recurrence relation:

int f( int n ) {

if ( n <= 1 ) {

return 1;

}

return f( n – 1 ) + f( n – 1 );

}

Homework Answers

Answer #1
recurrence relation for the given function f is
f(n) = 2f(n-1) + 1
    = 2(2f(n-2)+1) + 1
    = 2^2f(n-2)+2 + 1
    = 2^3f(n-3)+ 2^2 +2 + 1
    .....
    .....
    = 2^nf(n-n)+ ... + 2^2 +2 + 1
    = 2^nf(0)+ ... + 2^2 +2 + 1
    = 2^n+ ... + 2^2 +2 + 1
    = 2^(n+1)
    = O(2^n)

the run time of the following recursive functions as a recurrence relation is O(2^n)
Know the answer?
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
Similar Questions
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an...
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an argument and returns the sum of every other int from n down to 1. For example, the call sumEveryOther(10) should return 30, since 10 + 8 + 6 + 4 + 2 = 30. The call sumEveryOther(9) should return 25 since 9 + 7 + 5 + 3 + 1 = 25. Your method must use recursion.
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
Write a C++ recursive function that counts the number of nodes in a singly linked list....
Write a C++ recursive function that counts the number of nodes in a singly linked list. (a) Test your function using different singly linked lists. Include your code. (b) Write a recurrence relation that represents your algorithm. (c) Solve the recurrence relation using the iterating or recursive tree method to obtain the running time of the algorithm in Big-O notation.
ORIGINAL SOLUTION PLEASE Find an explicit formula for the following recurrence relation: 3an+1 - 4an =...
ORIGINAL SOLUTION PLEASE Find an explicit formula for the following recurrence relation: 3an+1 - 4an = 0 ; a1 = 5 Write a Python program that tests your result by generating the first 20 terms in the sequence using both the recursive definition and your explicit formula
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code...
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code that does the calculation. C. What is the recurrence relation for the number of multiplications? D. What is the efficiency class of the algorithm?
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Program should ask for input and be stored in the string and should return n amount of times.
Given the following function:      int C(int n, int k)                  {              
Given the following function:      int C(int n, int k)                  {                     if (k= =0) return 1;                        else return (C(n-1, k-1) * n)/k;                                       } What type of function is this? Recursive or Iterative. Explain your answer.
Consider the following recursive algorithm Algorithm S(n) if n==1 return 1 else return S(n-1) + n*n*n...
Consider the following recursive algorithm Algorithm S(n) if n==1 return 1 else return S(n-1) + n*n*n 1)What does this algorithm compute? 2) Set up and solve a recurrence relation for the number of times the algorithm's basic operation is executed. 3) How does this algorithm compare with the non-recusive algorithm for computing thius function in terms of time efficeincy and space effeciency?
Recurrence Relations Solve the following recurrence equation: f(n, k) = 0, if k > n f(n,k)...
Recurrence Relations Solve the following recurrence equation: f(n, k) = 0, if k > n f(n,k) = 1, if k = 0 f(n,k) = f(n-1, k) + f(n-1,k-1), if n >= k > 0
Consider the following recursive algorithm. Algorithm Test (T[0..n − 1]) //Input: An array T[0..n − 1]...
Consider the following recursive algorithm. Algorithm Test (T[0..n − 1]) //Input: An array T[0..n − 1] of real numbers if n = 1 return T[0] else temp ← Test (T[0..n − 2]) if temp ≥ T[n − 1] return temp else return T[n − 1] a. What does this algorithm compute? b. Set up a recurrence relation for the algorithm’s basic operation count and solve it.