Dynamic Programming21 sections · 916 units
Open in Course

Power Function - Base Cases

When to stop

You need two base cases:

1.1. x0=1x^0 = 1 for any xx.

2.2. x1=xx^1 = x (optional, but avoids one extra call). The second base case is not strictly necessary since x1=x×x0=x×1=xx^1 = x \times x^0 = x \times 1 = x. But adding it makes the code slightly faster. Either way works. Base cases are where the recursion stops. They handle the simplest possible inputs directly, without making recursive calls. Every recursive function needs at least one base case, or it will recurse forever and crash.

unnamed (14) (1).jpg