← all problems

Trace: fibonacci recursive calls 🌶️🌶️🌶️

Below is a recursive (non-memoized) Fibonacci method. Trace every call and every return as fib(4) actually executes, in order. Remember: in 'fib(n - 1) + fib(n - 2)', Java fully evaluates fib(n - 1) — including everything it calls — before fib(n - 2) is even called.

public int fib(int n) {    if (n <= 1) return n;    return fib(n - 1) + fib(n - 2);}


Call it as fib(4).

1. Trace every call and return event for fib(4), in the order they happen.

Add a row for every call and every return, in the order they actually happen — that's two rows per invocation. Call path: dotted numbering — the first call is 1; a call's own first recursive call is 1.1, its second is 1.2, and so on. Event: write call or return. Last column: the arguments passed on a call row, or the value returned on a return row.

Your score for your class is recorded when you click Submit all — checking individual questions doesn't save it. You can submit again to improve your score; your best one counts.