Recursion facts for kids
Recursion is a cool idea from mathematics and computer science. It means when something is defined or explained by using itself. Imagine a story where a character tells a story, and in that story, another character tells a story, and so on! That's a bit like recursion.
Contents
How Does Recursion Work?
When we talk about recursion in computer programs or math, it usually means a process that calls or refers to itself. Think of it like a set of instructions. If those instructions include a step that says "do these same instructions again," that's recursion.
For recursion to work properly, there must be a way for the process to stop. If it just kept calling itself forever, it would never finish! So, there's always a special "stopping point" or "base case." This is a simple version of the problem that doesn't need to call itself again.
When a recursive process calls itself, it usually works on a smaller or simpler version of the problem. This helps it solve big problems by breaking them down into tiny, manageable pieces.
An Example of Recursion
Let's look at an example using something called a "factorial." A factorial of a number (like 5!) means multiplying that number by all the whole numbers smaller than it, down to 1. So, 5! = 5 × 4 × 3 × 2 × 1 = 120.
Here's how you can think of factorial using recursion:
- If you want to find the factorial of a number (let's say `n`), you can say it's `n` multiplied by the factorial of `n-1`.
- For example, 5! is 5 multiplied by 4!.
- And 4! is 4 multiplied by 3!.
- This continues until you reach the "stopping point." The stopping point for factorials is when you need to find the factorial of 0. The factorial of 0 is always 1.
So, to find 5!:
- 5! = 5 × (4!)
- 4! = 4 × (3!)
- 3! = 3 × (2!)
- 2! = 2 × (1!)
- 1! = 1 × (0!)
- 0! = 1 (This is our stopping point!)
Now, we can work our way back up:
- 1! = 1 × 1 = 1
- 2! = 2 × 1 = 2
- 3! = 3 × 2 = 6
- 4! = 4 × 6 = 24
- 5! = 5 × 24 = 120
This example shows how a problem (finding 5!) is solved by breaking it into smaller, similar problems until a simple base case (0!) is reached.
Where Is Recursion Used?
Recursion is a powerful tool used in many areas:
In Computer Programming
Computer programmers use recursion to write programs. Sometimes, a program that uses recursion can be simpler to write and easier to understand than one that doesn't. It's especially good for problems that can be broken down into smaller, similar parts.
In Mathematics
In mathematics, recursion is used to prove theorems. This method is called induction. It's a way to show that if something is true for a starting point, and if it being true for one step means it's true for the next step, then it must be true for all steps.
In Art and Language
You can even see the idea of recursion in art and language:
- A fractal image is a picture that contains smaller versions of itself. If you zoom in, you see the same patterns repeating.
- In the rules of grammar, a sentence can be part of another sentence. For example, "The boy who ran fast won the race." The part "who ran fast" is like a mini-sentence inside the bigger one.
Images for kids
-
A visual form of recursion known as the Droste effect. The woman in this image holds an object that contains a smaller image of her holding an identical object, which in turn contains a smaller image of herself holding an identical object, and so forth. 1904 Droste cocoa tin, designed by Jan Musset
-
Ouroboros, an ancient symbol depicting a serpent or dragon eating its own tail.
-
Recently refreshed sourdough, bubbling through fermentation: the recipe calls for some sourdough left over from the last time the same recipe was made.
-
A recursive Wikipedia page
-
Recursive dolls: the original set of Matryoshka dolls by Zvyozdochkin and Malyutin, 1892
-
Front face of Giotto's Stefaneschi Triptych, 1320, recursively contains an image of itself (held up by the kneeling figure in the central panel).
See also
In Spanish: Recursión para niños