AlgoFrames

Count leaves of the call tree

Challenge · Trace the algorithm · about 8 min

A leaf of the call tree is a call that returns without calling again: fib(1) or fib(0). Before the tree of fib(6) grows, work out how many leaves it will have.

Example 1

Input:

{"n":3}

Output:

3

The tree of fib(3) has 3 leaves: fib(1), fib(1) and fib(0).

Constraints

  • The trace uses n = 6.

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

More Recursion trees: Fibonacci and repeated work problems