AlgoViz
← Back to the lesson
🧩 Puzzle · Apply Recursion

Unwind it

Run fact(5) the way the machine does. First push the calls DOWN — each fact(n) waits and calls fact(n-1) — until you hit the base case fact(1), which returns 1 on its own. Then unwind back UP: every frame multiplies in its own n as it returns, building the answer one pop at a time.

push downeach call waits for the one below it
fact(5)= 5 × fact(4)
fact(5) is on the stack. It can't answer yet — make it call fact(4).
Push calls down to the base case, then unwind: each frame returns n × the value below it.no misses