Vismo · Create · Explore · Topics · Guides · Pricing

Recursion on the call stack: 5! unwinds

This animation visualizes fact(5) as it pushes five stacked frames, one for each recursive call, until reaching the base case fact(0). It then shows the stack unwinding in reverse, with each frame computing and returning a value: 1, 1, 2, 6, 24, and finally 120. The visual makes clear why deep recursion consumes memory proportional to call depth, helping students connect abstract recursive code to concrete stack behavior and return-value propagation.

16:9 · Preview before teaching · automatic layout checks do not establish subject accuracy

The prompt that made it

fact(5) pushes five frames onto the call stack until the base case, then unwinds computing 1, 2, 6, 24, 120 as each frame returns; deep recursion means many frames of memory.

Make your own version

Make the next one in this series

Related animations

How A Perceptron Makes A Decision
How A Perceptron Makes A Decision

This animation visualizes a single perceptron processing weighted inputs, summing them with a bias, and passin…

From logic gates to arithmetic: the half adder
From logic gates to arithmetic: the half adder

This animation shows how a half adder circuit uses an XOR gate to compute the sum bit and an AND gate to compu…

Minimum spanning tree with Kruskal's algorithm
Minimum spanning tree with Kruskal's algorithm

A weighted graph is processed by sorting all edges from cheapest to most expensive, adding each one only if it…

Fibonacci: the recursion tree repeats work; memoisation removes it
Fibonacci: the recursion tree repeats work; memoisation removes it

This animation draws the full recursion tree for fib(5), showing all 15 calls and highlighting the repeated su…

Binary search tree: smaller left, larger right
Binary search tree: smaller left, larger right

Values 50, 30, 70, 20, 40, 60, 80, and 35 are inserted one at a time into a binary search tree, with each comp…

Hash tables: a formula decides where each key lives
Hash tables: a formula decides where each key lives

Seven buckets receive keys according to key mod 7, with collisions stacked as chains beneath each bucket. A lo…