GATE | GATE CS 2008 | Question 74
Consider the following C program
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] ; } |
chevron_right
filter_none
The running time of f1(n) and f2(n) are
(A)
(n) and
(n)
(B)
(2^n) and
(n)
(C)
(n) and
(2^n)
(D)
(2^n) and
(2^n)
(A) A
(B) B
(C) C
(D) D
Answer: (B)
Explanation: See Question 3 of https://www.geeksforgeeks.org/c-language-set-5/
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 2008 | Question 52
- GATE | GATE CS 2008 | Question 51
- GATE | GATE CS 2008 | Question 50
- GATE | GATE CS 2008 | Question 49
- GATE | GATE CS 2008 | Question 48
- GATE | GATE CS 2008 | Question 47
- GATE | GATE CS 2008 | Question 46
- GATE | GATE CS 2008 | Question 45
- GATE | GATE CS 2008 | Question 44
- GATE | GATE CS 2008 | Question 53
- GATE | GATE CS 2008 | Question 54
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 58
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 56



