Data Structures & AlgorithmsModerateProduct-company MCQ pattern
How many calls in total (including the first) does C(5, 2) make?
How many calls in total (including the first) does C(5, 2) make?
int C(int n, int k) {
if (k == 0 || k == n) return 1;
return C(n - 1, k - 1) + C(n - 1, k);
}- A. 20
- B. 15
- C. 10
- D. 19
Correct answer: D. 19
The leaves of the recursion tree each return 1 and add up to C(5, 2) = 10, so there are 10 leaves; every internal call has exactly 2 children, so internal calls = 10 − 1 = 9. Total 19. 10 is the value, not the call count.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- For n = 6, how many disk moves does this Tower of Hanoi function count, and how many calls of hanoi are made in total? c int hanoi(int n…
- A robot moves only right or down on a 3 × 4 grid of cells (3 rows, 4 columns) from the top-left cell to the bottom-right cell. The cell in…
- What is the length of the longest palindromic SUBSEQUENCE of CHARACTER?
- Coins of 1, 5, 6 and 8 are available in unlimited supply. For amount 11, how many coins does the 'largest coin first' greedy method use…
- Each job takes 1 unit of time; only one job runs at a time. Jobs (deadline, profit): J1 (2, 100), J2 (1, 19), J3 (2, 27), J4 (1, 25), J5…
- Characters a, b, c, d, e occur 4, 7, 9, 12 and 20 times. With an optimal Huffman code, how many bits are needed to encode the whole text?