Recursion

Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself. While it may not seem like much on the surface, recursion allows us to write elegant solutions to problems that may otherwise be very difficult to program.

Every recursive algorithm must follow these three rules:

  1. A recursive algorithm must have a base case.
  2. A recursive algorithm must change its state and move toward the base case.
  3. A recursive algorithm must call itself, recursively.

Here are a few programs that follow these rules of recursion:

Navigating the Towers of Hanoi Problem Using Recursion

Calculating the Sum of a List of Numbers Using Recursion

Reversing a String in Python Using Recursion