Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(6) and count every invocation of f, including the first call. How many calls to f are made in total?
- A. 8
- B. 30
- C. 15
- D. 25
Correct answer: D. 25
Each call spawns the recursive branches listed, so f(6) makes 25 invocations in total. The returned value 8 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
- Words ['bdc', 'dd', 'dba', 'ddc', 'ccb'] (each may be used at most once). A chain is a sequence of these words in which the first letter…
- Array A = [2, 3, 3, 4, 2, 2, 3, 5, 2]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- A trie keeps a counter at each node, and every word of the list W = ['ab', 'cc', 'ba', 'ca', 'ac', 'ba', 'cba', 'bba'] is inserted once…
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–F (1), B–E (1), B–F (1), C–D (1), D–F (1), D–G…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (14), A–F (12), B–D (12), C–D (8), C–E (1), E–F…
- 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→E (8)…