AlgoFrames

Repeated subproblems

Standard · Trace the algorithm · about 5 min

The tree of fib(5) is complete. Some calls recompute a fib(2) or fib(3) that an earlier call already worked out. Click every such repeated call.

Example 1

Input:

{"n":5}

Output:

5

Constraints

  • Count only fib(2) and fib(3) calls that are not the first with their n.

Learn the idea first: Recursion trees: Fibonacci and repeated work, a visual lesson.

More Recursion trees: Fibonacci and repeated work problems