Search⌘ K
AI Features

Overview of Recursion

Explore the concept of recursion, understanding how problems can be solved by functions calling themselves. Gain insight into real-world examples and computer science applications, preparing you to apply recursive thinking in coding challenges effectively.

What is recursion?

Defining a thing in terms of itself or of its own type is called recursion. It is used in a variety of disciplines. The most common application of recursion is in mathematics and computer science.

The Droste effect

A very common example to understand recursion is the Droste effect. You might be unfamiliar with this term but have likely seen it once in your life. A visual form of recursion is known as the Droste effect. Look at the figure below.

The lady in the image is painting a smaller image of herself, which is painting a much smaller image of herself. These three levels are identical. The only difference is the size.

Recursion in computer science

Recursion is a method of solving a problem where the solution depends on the solutions to the smaller instances of the same problem.

Have you ever noticed a tree? Its structure is an example of recursion in real life. Each branch can be seen as a smaller version of the tree.

Recursion is one of the central ideas of computer science. Problems can generally be solved by iteration, but we need to identify and index the smaller instances. Recursion solves such problems by using functions that call themselves from within their own code.