Semicolony ELI5 · comic

Recursion.

Nesting dolls: solve a problem by doing the same smaller version of it, until one is tiny enough to answer outright.

  1. Open this.
    1

    A big problem. The trick: it contains a smaller version of the very same problem.

  2. 2

    So do the same job — on the smaller piece.

  3. 3

    Each step stacks up, waiting, as the problem gets smaller and smaller.

  4. This one I just know.
    base case
    4

    Until the smallest case, simple enough to answer outright — the base case.

  5. 5

    Now the answers travel back up, each step finishing once the piece below it is solved.

  6. Uh oh — no bottom.
    6

    Forget the base case and it never stops — it just shrinks forever (stack overflow).

The same job, on a smaller piece each time, until a base case stops it.
Semicolony semicolony.dev/eli5/recursion/comic
← All ELI5 explainers