Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(12) and count every invocation of f, including the first call. How many calls to f are made in total?
- A. 162
- B. 81
- C. 60
- D. 119
Correct answer: D. 119
Each call spawns the recursive branches listed, so f(12) makes 119 invocations in total. The returned value 60 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
- Coins of denominations [9, 8, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 22?…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→C (9)…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (6), A–D (5), B–C (3), B–D (4), C–D (4). Among all spanning…
- Directed acyclic graph on vertices A, B, C, D, E, F with edges A→F, A→C, A→E, F→D, B→E, D→C. Among all topological orderings (every edge…
- Directed acyclic graph on vertices A, B, C, D, E, F with edges B→D, A→F, A→E, D→E, F→C. Among all topological orderings (every edge goes…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–C (6), A–D (6), B–C (1), B–D (5), C–E (4), D–E (4). Among all…