GATE Computer ScienceHardGATE CS
The function below is called as g(12, 5). def g(n, k): if k == 0 or k == n: return 1 return g(n-1, k-1) + g(n-1, k) How many calls to g are made in total (including the first)?
- A. 1583
- B. 1584
- C. 1575
- D. 792
Correct answer: A. 1583
g(n, k) returns C(n, k) by adding leaf values of 1, so the recursion tree has C(12, 5) = 792 leaves. In a full binary tree the number of internal nodes is leaves − 1, so total calls = 2·792 − 1 = 1583.
More Algorithms questions
- Ten words are inserted into an initially empty trie (one node per character, plus a root): cat, car, cart, care, dog, dot, do, carbon…
- A directed graph has edges (weights): S→A 2, S→B 2, S→C 3, A→D 2, A→E 3, B→D 2, B→E 1, B→F 3, C→E 1, C→F 2, D→T 2, E→T 3, F→T 1. How many…
- Twelve keys 24, 17, 31, 9, 22, 5, 38, 13, 2, 27, 6, 20 are used to build a min-heap in an array in two ways: (1) by inserting them one at…
- Which is the tight asymptotic solution of T(n) = T(n/3) + T(2n/3) + n/log₂ n (with T(1) = 1)?
- A flow network has directed edges (capacity): s→a 4, s→b 3, a→b 2, a→c 2, b→c 2, b→d 3, c→t 4, d→t 2, c→d 1. Let F be the maximum s–t flow…
- For the Petersen graph (10 vertices, 15 edges, 3-regular, independence number 4), let VC be the size of a minimum vertex cover and MM the…