Fifteen calls for five.
transcript
Weight of five makes two calls. Each of those makes more calls. The calls multiply quickly. Let us draw all of them.
The first call makes two calls. Follow the left side to the leaves. Weight of one is called again. The tree has fifteen calls.
Fifteen calls were made. Only six questions are different. Nine calls asked a question again. That is waste, and it grows fast.
The tree has fifteen calls. But the stack is only five frames deep. The stack holds one path at a time. Calls decide time. Depth decides memory. A recursion can be wide and still shallow.
A call counts itself. It adds the calls under each child. One plus nine plus five is fifteen. The count follows the function.
Weight of forty has three hundred thirty-one million calls. Only forty different questions exist. A cache answers each one once.
Repeated calls are wasted work. Full breakdown in the lecture.