Algorithm Design: Recursive Algorithms

Understand recursive algorithms with the help of an example.

Recursive algorithms

Recursion is one of the most ubiquitous algorithmic concepts. Simply put, an algorithm is recursive if it calls itself.

The Towers of Hanoi puzzle consists of three pegs, which we label from left to right as 1, 2, and 3, and a number of disks of decreasing radius, each with a hole in the center. The disks are initially stacked on the left peg (peg 1) so that smaller disks are on top of larger ones. The game is played by moving one disk at a time between pegs.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.