Question

Write a Recursive Function Algorithm to find the terms of following recurrence relation. t(1)=3 t(k)=2×t(k-1)-5 (n>1)....

Write a Recursive Function Algorithm to find the terms of following recurrence relation.

t(1)=3

t(k)=2×t(k-1)-5 (n>1).
and (ii) If you call z←t(4) in a program then what value the program will use for z?   

Homework Answers

Answer #1

Algorithm:

Algorithm Recursive(n):
        
        if n = 1
        then return 3 
        
        else x = Recursive(n - 1)
             x = (2 * x) - 5    
        
        return x 
        
        endif

Trace of algorithm for t(4)

Manual trace of t(4):

Below is the C language code of this algorithm:

#include <stdio.h>

int Recursive(int n){
   int x;
   if(n == 1){
       return 3;
   }
    else{
        x =  Recursive(n -1);
        x = (2*x) - 5;
    }
    return x;

}


int main()
{
    int z = Recursive(4);
    printf("ans: %d \n", z);
    return 0;
}

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
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?
java data structure question - Consider the following recurrence function" f(1)=1; f(2)=2; f(3)=3; f(4)=2; f(5)=2 f(n)...
java data structure question - Consider the following recurrence function" f(1)=1; f(2)=2; f(3)=3; f(4)=2; f(5)=2 f(n) = 2 * f(n -1) + f(n – 5) for n >= 6 Write a program to demonstrate this recurrence relation (recursive method) and demonstrate it for the values n = 6, 7, 10, and 12; Create a second method that solves the same problem using an iterative solution. Modify your test program to show that both the recursive method and the iterative methods...
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.
Consider the following recursive algorithm. Algorithm Mystery(n) if n=1 then Execute Task A; // Requires Θ(1)...
Consider the following recursive algorithm. Algorithm Mystery(n) if n=1 then Execute Task A; // Requires Θ(1) operations else Mystery(n/3); Mystery(n/3); Mystery(n/3); Execute Task B;  //Requires 2n operations end if Let C(n) be the complexity of Mystery(n). Use the method of backward substitution to determine C(n) in three steps. a) Write the recurrence relation for C(n) including the initial condition. b) Write at least two substitution steps for C(n) and identify the pattern. c) Determine the complexity class of the algorithm in...
Design a recursive algorithm to compute 3^n based on the formula 3^n=3^(n−1) + 3^(n−1) + 3^(n−1)....
Design a recursive algorithm to compute 3^n based on the formula 3^n=3^(n−1) + 3^(n−1) + 3^(n−1). Also do the recurrence relation.
Solve the Recurrence Relation T(n) = 2T(n/3) + 2, T(1) = 1
Solve the Recurrence Relation T(n) = 2T(n/3) + 2, T(1) = 1
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 ); }
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
Solve the following recurrence relation T(1) = c1 T(n) = 2*T(n/2) + c2
Solve the following recurrence relation T(1) = c1 T(n) = 2*T(n/2) + c2
Consider the recurrence relation T(1) = 0, T(n) = 25T(n/5) + 5n. (a) Use the Master...
Consider the recurrence relation T(1) = 0, T(n) = 25T(n/5) + 5n. (a) Use the Master Theorem to find the order of magnitude of T(n) (b) Use any of the various tools from class to find a closed-form formula for T(n), i.e. exactly solve the recurrence. (c) Verify your solution for n = 5 and n = 25.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT