How to use the visualizer

1. Pick an example — or write your own

The preset picker loads a classic recursive function into the editor with a ready-made initial call; its trace appears instantly. You can edit anything: the code (nested helper functions are fine) and the initial call, e.g. is_palindrome('racecar'). The initial call must be a single expression that calls one of your functions.

2. Run & trace

Press Run & trace (or Ctrl+Enter / Cmd+Enter in the editor). The first run downloads the Python runtime into your browser, which can take a little while — the button shows progress. Obvious mistakes (indentation, brackets, disabled features like imports) are reported with line numbers before anything runs. Big runs stop at a safety limit and the app asks before raising it.

3. Replay the recursion

A successful run replays automatically. Use the controls to step forward and back, play/pause, change speed, or jump to either end. The call stack shows the frames alive at the current step, the executing one on top. The call tree grows one call at a time; completed calls turn muted and show their return value, and dashed boxes mark repeated calls with the same arguments (recomputed work). Click any node for its details; a text version of the tree sits below it.

4. Time & space analysis

Open the Time & space analysis panel under the controls. Time follows the course's recurrence-relation method as a 5-step derivation, with a cross-check against the calls your run actually made. Space starts from the deepest the stack really got and generalizes via the recurrence. The analysis states its assumptions and its confidence — when it says a pattern needs instructor review, take that literally.

Limits worth knowing

  • Traces are capped (500 events / 100 frames by default; you confirm each raise, up to 2000 / 500). Keep inputs small — fibonacci(12) is already 465 calls.
  • The recurrence method recognizes the course patterns (one call with n − k or n/2; two calls with n − k or n/2). Anything else is reported honestly as unrecognized.
  • Your code never leaves the browser — see About & privacy.

The course notes behind this

The Recursion chapter, in the order the course teaches it. This app animates what these pages draw by hand, so read them alongside it rather than instead of it.

  • Introduction to recursionthe run-time stack as a stack of plates — one layer per call, holding that call's own parameters and locals. That stack is the call stack panel.
  • Writing a recursive functionstating the base case and the recursive case, worked on factorial. Every preset here is built from those two halves.
  • How does recursion work?factorial traced by hand, each call pushing a frame and each return unwinding one — the replay, on paper.
  • Analysis of recursive functionsT(n) = 6(n − 1) + 3 = 6n − 3, so O(n): the recurrence-relation method the analysis panel follows.
  • Drawbacks of recursionstack space, call overhead, and when a loop is the better answer. The dashed repeated-call boxes in the tree are this page's argument, drawn.