Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(9) and count every invocation of f, including the first call. How many calls to f are made in total?
- A. 37
- B. 25
- C. 50
- D. 19
Correct answer: A. 37
Each call spawns the recursive branches listed, so f(9) makes 37 invocations in total. The returned value 19 and a smaller argument's call count are different quantities.
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
- A binary tree with distinct letters has preorder DAEFCB and inorder EADCFB. What is its postorder traversal (left, right, root), written…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–E (1), A–F (1), B–D (1), E–F (1) (weights ignored)…
- 5 × 4 grid, rows top to bottom ('#' = blocked, '.' = open): ..#. / ...# / ...# / ..#. / ..... Count the paths from top-left to…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: B–D (1), A–D (1), B–F (1), C–D (1), D–F (1), B–E (1)…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(7) and count every invocation of f…
- Array [27, 5, 12, 25, 10, 1, 22, 2] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the…