The GATE Grind

GATE 2008 CS – Question 75

Programming and Data Structures · Recursion · 2 marks · Multiple choice

Consider the C functions (assume N>n):

int f1(int n) {
 if(n==0 || n==1) return n;
 return 2*f1(n-1)+3*f1(n-2);
}
int f2(int n) {
 int i; int X[N],Y[N],Z[N];
 X[0]=Y[0]=Z[0]=0;
 X[1]=1;Y[1]=2;Z[1]=3;
 for(i=2;i<=n;i++) {
  X[i]=Y[i-1]+Z[i-2];
  Y[i]=2*X[i];Z[i]=3*X[i];
 }
 return X[n];
}

What values do f1(8), f2(8) return?

  1. 1661 and1640
  2. 59 and59
  3. 1640 and1640
  4. 1640 and1661

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) 1640 and1640

Explanation

We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort

More Recursion questions

All Recursion questions →