Recursion is when something repeats itself using smaller versions of itself, like a never-ending story that keeps getting shorter.
Imagine you have a set of Russian nesting dolls, those big ones that open up to show smaller ones inside, and so on. Each doll looks just like the one before it, but a little bit smaller. That’s recursion in action: each doll is a smaller version of the one before it.
Like a never-ending game
Think about climbing stairs. If you’re standing on step 1 and want to get to step 5, you can say: “I’ll go from step 1 to step 2, then do the same thing again, from step 2 to step 3, and so on.” That’s like recursion too! You keep doing the same action (climbing one stair) but with a smaller problem each time.
A real-life example
Imagine you're eating cookies. If there are 10 cookies left, you eat one and then say, “Now I have 9 cookies, let’s do this again!” You keep doing that until all the cookies are gone. That's recursion: you repeat the same action (eating a cookie), but with fewer cookies each time.
It’s like having a copy of yourself helping you finish the job!
Examples
- A child asks their parent for a cookie, and the parent says they need to ask another parent first.
- Drawing a spiral by repeating smaller spirals inside it.
- Counting down from 10 to 0 by repeatedly counting down one less.
Ask a question
See also
- What on Earth is Recursion? - Computerphile?
- What are recursive calls?
- What are recursive processes?
- What are persistent data structures?
- How Does Recursion in 100 Seconds Work?