A stopping criterion is the terminating condition that lets a recursive algorithm return a direct result instead of making another recursive call. In recursive Swift functions, it is usually expressed as a base case; without one, execution can continue indefinitely. section 1.1
A useful recursive design separates two cases:
- Base case: recognize the smallest or directly solvable input and return its result. section 1.1 section 1.5
- Recursive case: reduce a larger problem until a later call reaches the stopping criterion. section 1.5
- Check every recursive path: a mathematically valid stopping condition does not prevent poor performance when calls branch repeatedly. section 1.1
Fibonacci
For Fibonacci, 0 and 1 are stopping values because they do not require adding earlier terms. A Swift implementation can test n < 2 and return n; larger values use fib2(n - 2) + fib2(n - 1). This prevents infinite recursion, although the naive branching version still performs many repeated calls. section 1.1
Towers of Hanoi
For Towers of Hanoi, moving one disc is the stopping criterion. Larger towers recursively move n - 1 discs, move the remaining disc, and move the n - 1 discs again. The base case therefore anchors each three-step decomposition. section 1.5










