Dynamic Programming21 sections · 916 units
Open in Course

Factorial - Base Case

What's the simplest?

The simplest factorial is 0!=10! = 1. This is defined mathematically and gives you a natural stopping point. When you recursively call factorial with smaller and smaller numbers, you will eventually reach 00.

At that point, you return 11 immediately without any more recursion. Some definitions also treat 1!=11! = 1 as a base case, which works too. Either way, the base case must be explicit and return a value directly. This is the anchor that stops the chain of recursive calls.

unnamed (7) (1).jpg