Start here · Essential guide
Recursive Algorithm Examples
Recursive algorithm examples in Python: factorial, binary search, tree traversal, Tower of Hanoi, and merge sort, with base cases explained for each.
Algorithms
How recursive functions work, which sorting algorithms use recursion and why some coding rules ban it.
Start here · Essential guide
Recursive algorithm examples in Python: factorial, binary search, tree traversal, Tower of Hanoi, and merge sort, with base cases explained for each.
A recursive function calls itself on a smaller problem until it reaches a base case. Covers the call stack, base cases, stack overflow and common mistakes.
Merge sort and quicksort are the best-known recursive sorts, and Timsort avoids deep recursion. Bubble, insertion and heapsort usually use loops.
The idea that NASA banned recursion comes from a 2006 JPL coding guideline for safety-critical code. It restricts recursion so the code can be analyzed.
Related topics