recursion
C2Pronunciation
UK
- /rɪkˈɜːʃən/
US
- /rɪkˈɜːʃən/
Description
- repeating process
- self-reference
- self-similar structure
Recursion is like those Russian nesting dolls: each doll contains a smaller version of itself. In programming and mathematics, it means defining something in terms of itself. Think of a set of instructions that use the same steps again to solve a problem, breaking it into smaller, similar parts until an answer is reached. It is a useful way to handle complex tasks by repeating a process with changed inputs. You might also meet this idea in art or literature, such as a story within a story or a picture that includes itself.
Recursion describes a process in which something is defined in terms of itself. It is not simply endless repetition; it is usually a controlled pattern in which each step leads to a smaller or simpler version of the same task. The most common context for this word is computer science and mathematics, where it is used to solve complex problems. Imagine you want to calculate the factorial of a number (like 5! = 5 x 4 x 3 x 2 x 1). A recursive function can define the factorial of "n" as "n multiplied by the factorial of n-1," continuing until it reaches the base case of 0!, which is defined as 1. This breaks a large calculation into smaller, self-similar steps.
However, recursion isn't limited to code. It appears in many areas of life and thought. In art, you might see recursive patterns, such as fractals, where similar shapes repeat at different scales. In literature, a story within a story is an example of narrative recursion. Even language itself is recursive: consider how we embed clauses within clauses to create complex, layered sentences.
The key to understanding recursion is recognizing its self-referential nature and, in many technical uses, the need for a "base case" that stops the process. Without that stopping point in a program, the process may continue until it fails. Whether it is a mathematical function, a piece of art, or a literary device, recursion involves a pattern that refers back to itself, often by repeating a similar form at a smaller level until a result or complete shape appears.
Examples
- 1
Programming example
The lesson starts with a simple function that uses recursion to search a folder of files.
- 2
Learning difficulty
Many beginners find recursion confusing until they see where the process stops.
- 3
Base case
Without a clear base case, recursion can keep going until the program crashes.
Domain
base case
the condition that stops the repeated process
- 4
Programmer joke
"To understand recursion, you must first understand recursion" is a common joke among programmers.
Note
This joke repeats the word on purpose to imitate recursion.
Forms and spellings
2 forms open this card.
Main spelling
- recursionnoun
Forms
- recursionspluralnoun