Named puzzles and recreational problems, grouped by the technique that solves them. Each linked page has the full treatment; this is the index and the βwhat technique does this needβ map.
Problems, not algorithms
These are questions whose answers happen to be famous β distinct from the named algorithms, which are methods. The full set lives in Classical Problems.
Recreational classics
| Puzzle | Technique |
|---|---|
| Tower of Hanoi | recursion; moves; the -th move is disk |
| Josephus problem | recurrence, or bit rotation for |
| N-Queens | backtracking with bitmasks |
| Knightβs tour | backtracking + Warnsdorffβs rule |
| 8- / 15-puzzle | A*, bidirectional BFS; a parity invariant decides solvability |
| Water jug | BFS on states; solvable iff target |
| Wolf, goat and cabbage | BFS on a small state space |
| Bridge and torch | greedy / small DP |
| Lights Out | Gaussian elimination |
| Sudoku | Dancing Links / exact cover |
| Magic square, Latin square | direct construction; see Classic Constructions |
| Pancake sorting | greedy; flips |
| Peg solitaire | an invariant (a colouring argument) |
| KΓΆnigsberg bridges | Eulerian path conditions |
Probability puzzles
| Puzzle | Answer |
|---|---|
| Monty Hall | switching wins with probability |
| Birthday paradox | 23 people for 50% |
| Coupon collector | |
| 100 prisoners and the boxes | cycle-following gives |
| Secretary problem | reject the first , then take the best so far |
| Poisoned wine | binary encoding: testers |
The 100 prisoners result is the most surprising: a strategy raising the success probability from to , using nothing but the cycle structure of a random permutation.
Number puzzles
| Puzzle | Technique |
|---|---|
| Trailing zeroes of $n!$ | Legendre: |
| Derangements | |
| The Catalan family | brackets, triangulations, BSTs β all |
| Chicken McNugget / Frobenius | for coprime |
| Staircase counting | Fibonacci |
| Digit sums, repunits, palindromic numbers | digit DP |
Trailing zeroes β the derivation
, and always has more factors of 2 than of 5, so the count is :
long long trailingZeroes(long long n) {
long long c = 0;
for (long long p = 5; p <= n; p *= 5) c += n / p;
return c;
}. In base , factor and take .
Array and sequence classics
| Puzzle | Technique |
|---|---|
| Maximum subarray | Kadane |
| Trapping rain water | two pointers, or monotonic stack |
| Largest rectangle in a histogram | monotonic stack |
| Majority element | Boyer-Moore voting |
| Dutch national flag | three-way partition |
| Celebrity problem | elimination |
| Gas station / circular tour | greedy with a running deficit |
| Stock buy and sell | greedy or DP by transaction count |
| Next greater element | monotonic stack |
Optimisation classics
| Problem | Status |
|---|---|
| Egg dropping | DP; a binomial closed form exists |
| Knapsack | DP; NP-hard |
| Coin change | DP; greedy fails in general |
| Rod cutting | unbounded knapsack |
| Assignment | Hungarian, |
| Stable marriage | Gale-Shapley, |
| TSP | NP-hard; Held-Karp for |
| Subset sum / partition | NP-hard; pseudo-polynomial DP |
See also: Classical Problems Β· Problem Pattern Recognition Β· Named Algorithms