Forgood.dev
weekly

Explain complex concepts like you’re 5 years old. Tools, hacks and more.

100% free. Unsubscribe anytime.

Check out a recent issue:

🍽️Recursion Explained to a six years old

№10 •
№10 •

Someone in a movie theater asks you what row you’re sitting in.

You don’t want to count, so you ask the person in front of you what row they are sitting in,

The person in front will ask the person in front of them.

This will keep happening until word reaches the front row, and it is easy to respond: “I’m in row1!”

From there, the correct message (incremented by one each row) will eventually make its way back to the person who asked.

Why this is a good explanation?

It gets across three points:

  1. There are some questions that may be inherently recursive and that some questions are easier to solve recursively.
  2. The question I am asking (“what row am I in?”) can be rephrased recursively as: “how many people are in front of me +1?” With a base case of zero people in front of me.
  3. It aslo illustrates the idea of a recursive call stack and how calls are pushed on then popped off the stack.

An onion is an onion skin with an onion inside.

This video explained it pretty well, give it a watch:

Best,

Abi