Computing Atlas

How Computing Was Built
Sign In
Text size
100%
Theme
Concept

Recursion

Technique

Recursion is a way of solving a problem by having a procedure call itself on a smaller version of the same problem, with a base case that stops the calls once the problem is simple enough to answer directly. It is one of computing's central organizing ideas, letting problems that are naturally self similar, walking a tree shaped data structure or defining a mathematical sequence, be expressed compactly, and it was given a rigorous mathematical footing well before general purpose computers existed, in Alonzo Church's 1930s lambda calculus and Kurt Gödel's earlier work on recursive functions.

Facts
Disputed
Origin Year
1960 2
The mathematical theory of recursive functions was formalized in the 1930s by Church, Godel and Kleene; John McCarthy brought recursion into practical programming with Lisp around 1958 to 1960, so the concept's origin year depends on whether the mathematics or the programming language is being dated.
Core Principle
A procedure that solves a problem by calling itself on a smaller instance of the same problem, until a base case is reached. 1
FAQs

Is recursion better than using a loop?

They are equally expressive, so the choice depends on the problem and the language.

Neither is strictly better, because the two are equally expressive: recursion can be replaced by iteration with an explicit call stack, and iteration can be replaced with tail recursion. Which is preferable depends on the problem and the language. In imperative programming, iteration is usually preferred for simple recursion because it avoids the overhead of function calls and call stack management, while recursion is generally used for multiple recursion. In functional languages recursion is preferred, since tail recursion optimization leaves little overhead.
Connections

Associated With

Source Wikipedia: Recursion (Computer Science)

In Field

Source Encyclopedia Britannica: Computer ScienceEncyclopedia Britannica Editors

Technique Used By

Source Baum-Welch algorithm (Wikipedia)
Source Wikipedia: Berlekamp's algorithm
Source Bitonic sorter (Wikipedia)
Source Wikipedia: Bucket sort
Source Edmonds' Algorithm (Wikipedia)
Source Wikipedia: Exponentiation by squaring
Source Heap's Algorithm (Wikipedia)
Source HITS algorithm (Wikipedia)
Source Integer square root (Wikipedia)
Source Wikipedia: Kosaraju's Algorithm
Source PageRank Algorithm (Wikipedia)
Source Wikipedia: Polynomial greatest common divisor
Source Stoer-Wagner algorithm (Wikipedia)
Source Stooge sort (Wikipedia)
Source Strand sort (Wikipedia)
Source Wikipedia: Tarjan's Strongly Connected Components Algorithm
Source Toom-Cook multiplication (Wikipedia)
Source Trial division (Wikipedia)
Sources
1. Encyclopedia Britannica: Computer Science
Encyclopedia Britannica Editors, Encyclopaedia Britannica Inc, 2024View the Source
2. Wikipedia: Recursion (Computer Science)
Wikimedia FoundationHistory
Quote, History
The early work done by Church, Gödel, Kleene, and Turing on recursive function and computability laid the groundwork that made recursion possible in programming languages.
View the Source
Wikipedia: Bucket sort
Technique Used By: Bucket Sort, Lead
Quote, Technique Used By: Bucket Sort, Lead
Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm.
View the Source
Wikipedia: Tarjan's Strongly Connected Components Algorithm
Wikimedia FoundationTechnique Used By: Tarjan's Strongly Connected Components Algorithm, Article body
Quote, Technique Used By: Tarjan's Strongly Connected Components Algorithm, Article body
Unlike in depth-first search, when the depth-first search recursively visits a node v and its descendants, those nodes are not all necessarily popped from the stack when this recursive call returns.
View the Source
Wikipedia: Kosaraju's Algorithm
Wikimedia FoundationTechnique Used By: Kosaraju's Algorithm, Article body
Quote, Technique Used By: Kosaraju's Algorithm, Article body
For each vertex u of the graph do Visit(u), where Visit(u) is the recursive subroutine: If u is unvisited then: Mark u as visited.
View the Source
Wikipedia: Exponentiation by squaring
Technique Used By: Exponentiation by Squaring Algorithm, Article body
Quote, Technique Used By: Exponentiation by Squaring Algorithm, Article body
It follows that the number of recursive calls is ⌈ log 2 ⁡ n ⌉ , {\displaystyle \lceil \log _{2}n\rceil ,} the number of bits of the binary representation of n.
View the Source
Baum-Welch algorithm (Wikipedia)
Technique Used By: Baum-Welch Algorithm, Lead
Quote, Technique Used By: Baum-Welch Algorithm, Lead
The Baum-Welch algorithm, the primary method for inference in hidden Markov models, is numerically unstable due to its recursive calculation of joint probabilities.
View the Source
Bitonic sorter (Wikipedia)
Technique Used By: Bitonic Mergesort, Article body
Quote, Technique Used By: Bitonic Mergesort, Article body
With the sorter for k = 1 {\displaystyle k=1} , we can recursively create a sorter of higher order.
View the Source
Stoer-Wagner algorithm (Wikipedia)
Technique Used By: Stoer-Wagner Algorithm, Lead
Quote, Technique Used By: Stoer-Wagner Algorithm, Lead
In graph theory, the Stoer-Wagner algorithm is a recursive algorithm to solve the minimum cut problem in undirected weighted graphs with non-negative weights.
View the Source
Edmonds' Algorithm (Wikipedia)
Technique Used By: Edmonds' Algorithm, Article body
Quote, Technique Used By: Edmonds' Algorithm, Article body
The algorithm has a recursive description.
View the Source
Toom-Cook multiplication (Wikipedia)
Technique Used By: Toom-Cook Multiplication, Lead
Quote, Technique Used By: Toom-Cook Multiplication, Lead
The multiplication sub-operations can then be computed recursively using Toom-Cook multiplication again, and so on.
View the Source
HITS algorithm (Wikipedia)
Technique Used By: HITS Algorithm, Article body
Quote, Technique Used By: HITS Algorithm, Article body
Authority and hub values are defined in terms of one another in a mutual recursion.
View the Source
Strand sort (Wikipedia)
Technique Used By: Strand Sort, Lead
Quote, Technique Used By: Strand Sort, Lead
Strand sort is a recursive sorting algorithm that sorts items of a list into increasing order.
View the Source
Heap's Algorithm (Wikipedia)
Technique Used By: Heap's Algorithm, Article body
Quote, Technique Used By: Heap's Algorithm, Article body
Described recursively as a decrease and conquer method, Heap's algorithm operates at each step on the k {\displaystyle k} initial elements of the collection.
View the Source
PageRank Algorithm (Wikipedia)
Technique Used By: PageRank Algorithm, Article body
Quote, Technique Used By: PageRank Algorithm, Article body
The PageRank of a page is defined recursively and depends on the number and PageRank metric of all pages that link to it ("incoming links").
View the Source
Wikipedia: Berlekamp's algorithm
Technique Used By: Berlekamp's algorithm, Article body
Quote, Technique Used By: Berlekamp's algorithm, Article body
The algorithm may then be applied recursively to these and subsequent divisors, until we find the decomposition of f ( x ) {\displaystyle f(x)} into powers of irreducible polynomials (recalling that the ring of polynomials over a finite field is a unique factorization domain).
View the Source
Wikipedia: Polynomial greatest common divisor
Technique Used By: Polynomial Greatest Common Divisor, Lead
Quote, Technique Used By: Polynomial Greatest Common Divisor, Lead
These algorithms proceed by a recursion on the number of variables to reduce the problem to a variant of the Euclidean algorithm.
View the Source
Trial division (Wikipedia)
Technique Used By: Trial division, Article body
Quote, Technique Used By: Trial division, Article body
When a trial division is successful, the process is applied recursively to the resulting quotient.
View the Source
Integer square root (Wikipedia)
Technique Used By: Integer square root, Article body
Quote, Technique Used By: Integer square root, Article body
It recursively splits the input number into high and low halves, computes the square root of the higher half, and then determines the lower half algebraically.
View the Source
Stooge sort (Wikipedia)
Technique Used By: Stooge sort, Lead
Quote, Technique Used By: Stooge sort, Lead
Stooge sort is a recursive sorting algorithm.
View the Source
Recursion (Wikipedia)
In Group: Algorithm Design Strategies, Lead
Quote, In Group: Algorithm Design Strategies, Lead
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself.
View the Source
Comments (0)
No comments yet. Be the first to share a thought.
Reader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.