StackOverflowErrorEach call waits on the stack until the base case returns, then results combine going back up.
Move n disks from one peg to another (using a third as helper), never placing a larger disk on a smaller one — a textbook example of elegant recursive thinking, needing 2ⁿ − 1 moves.
Self-similar patterns (e.g. the Koch snowflake) generated by recursively applying the same drawing rule to smaller and smaller pieces.
Recursively try a choice, and if it leads to a dead end, undo it and try the next option — used for puzzles like mazes, Sudoku, or the N-Queens problem.
| Notation | Name | Example |
|---|---|---|
O(1) | Constant | array access by index |
O(log n) | Logarithmic | binary search |
O(n) | Linear | scanning a list once |
O(n log n) | Linearithmic | efficient sorts (merge/quick sort) |
O(n²) | Quadratic | nested loop over the same data |
O(2ⁿ) | Exponential | naive recursive Fibonacci |
Big O describes how an algorithm's running time (or memory) grows as input size n grows — it's about scalability, not exact runtime, and helps compare algorithms independent of hardware.