• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE CS 2008 | Question 74

Consider the following C program c
int f1(int n)
{
  if(n == 0 || n == 1)
    return n;
  else
    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] ;
}
The running time of f1(n) and f2(n) are (A) [Tex]\\theta[/Tex](n) and [Tex]\\theta[/Tex](n) (B) [Tex]\\theta[/Tex](2^n) and [Tex]\\theta[/Tex](n) (C) [Tex]\\theta[/Tex](n) and [Tex]\\theta[/Tex](2^n) (D) [Tex]\\theta[/Tex](2^n) and [Tex]\\theta[/Tex](2^n)

(A)

A

(B)

B

(C)

C

(D)

D

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments