Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(8) and count every invocation of f, including the first call. How many calls to f are made in total?
- A. 25
- B. 13
- C. 17
- D. 34
Correct answer: A. 25
Each call spawns the recursive branches listed, so f(8) makes 25 invocations in total. The returned value 13 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
- Directed graph on vertices A, B, C, D, E, F, G with edges F→B, E→B, G→E, C→G, E→D, F→D, F→C, F→E, G→F, C→B, G→A. How many strongly…
- Keys [49, 47, 26, 15, 3, 33, 12, 19, 21] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Directed weighted graph on vertices A, B, C, D, E with edges A→C (6); A→E (2); C→A (-2); C→B (1); D→A (1); E→C (5); C→E (3); E→D (2); D→E…
- Rooted tree with root 0 and vertices 0 to 8; the edges are 0–1, 1–2, 2–3, 1–4, 1–5, 4–6, 4–7, 6–8 (parent–child). Every edge has length 1…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: B–E (3), C–E (4), B–C (8), E–F (2), D–F (7)…
- Array [28, 17, 3, 22, 8, 23, 10] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…