← all problems

Trace: factorial recursive calls 🌶️🌶️

Below is a recursive factorial method. Trace every call and every return as factorial(4) actually executes, in order.

public int factorial(int n) {    if (n <= 1) return 1;    return n * factorial(n - 1);}


Call it as factorial(4).

1. Trace every call and return event for factorial(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.