Nepedia
Back to Discover
Independent Reader
💻

Recursion (computer science)

technology Maturity 7-9 Next article →

Computers use a special way to solve problems. This way is called recursion. It happens when a function calls itself. A function is a set of instructions for a task.

recursiveTree
recursiveTree

Recursion works by breaking a big job into smaller parts. Each part is a smaller version of the same problem. To work well, recursion needs two main parts. The first is the recursive case. This part breaks the task down. It makes the problem smaller each time.

Sierpinski triangle turtle
Sierpinski triangle turtle

The second part is the base case. This is a stop rule. It tells the computer when to stop. The base case uses the simplest possible input. Without a base case, the computer might never stop. This can cause errors.

Tower of Hanoi
Tower of Hanoi

There are different kinds of recursion. Single recursion uses one self-call. Multiple recursion uses more than one. Some recursion is also indirect. This is when one function calls another. Then, that second function calls the first one back. This creates a chain of tasks. Recursion is a core idea in computer science. It helps us write code in a natural way.

179 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (5)
File:recursiveTree.JPG
recursiveTree.JPG
File:Sierpinski triangle turtle.gif
Sierpinski triangle turtle.gif
File:Recursive1.svg
Recursive1.svg
File:Recursive2.svg
Recursive2.svg
File:Tower of Hanoi.jpeg
Tower of Hanoi.jpeg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.