The Three Laws of RecursionΒΆ

Like the robots of Asimov, all recursive algorithms must obey three important laws:

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

A base case is the condition that allows the algorithm to stop recursing.

We must arrange for a change of state that moves the algorithm toward the base case.

Next Section - Programming Exercises