GATE Computer ScienceEasyGATE CS (PYQ pattern)
int f(int n) { if (n == 0) return 1; return f(n - 1) + f(n - 1); } How many calls to f (including the first) does f(10) make?
- A. 1024
- B. 2047
- C. 1023
- D. 11
Correct answer: B. 2047
The call tree is a complete binary tree with levels n = 10, 9, ..., 0, so 2^11 - 1 = 2047 calls (not 2^10).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 30, 10, 20, 50, 40, 60, 45 are inserted into an initially empty AVL tree in this order. What are the root and the total number of…
- Which one of the following is NOT a possible pop sequence when 1, 2, 3, 4, 5 are pushed in order (pops interleaved arbitrarily)? P: 2 1 4…
- 125 keys are hashed uniformly and independently into 50 chains of a hash table. What are the expected number of keys examined in an…
- The preorder and inorder traversals of a binary tree are 7 3 1 2 5 4 6 and 1 3 2 7 4 5 6 respectively. What is its postorder traversal?
- int a[] = {2, 4, 6, 8, 10}; int p = a + 1, q = a + 4; printf("%d %d %d", p + q, (q - 2), q - p); What is printed?
- int f(void) { static int c = 0; return ++c; } int main() { int x = f() || f(); int y = f() && f() > 3 ? f() : -f(); printf("%d %d %d", x…