Cheatsheet
Every formula on one page.
One page, every formula. If something here is unclear, follow the link to its topic.
Logs & exponents
Details: Topic 0
Sums
Details: Topic 0
| Sum | Closed form | Θ |
|---|---|---|
| last term | ||
| () | ||
| () | constant | |
Proof templates
- Induction: base case → hypothesis → prove by writing it as " + new piece".
- Contradiction: assume the opposite → derive something impossible → so the claim holds.
- Contraposition: to prove , prove .
- Loop invariant: Initialization · Maintenance · Termination (substitute the exit value, e.g. ).
- Correctness = partial correctness + termination.
Algorithms
| Best | Worst | Extra space | Stable | |
|---|---|---|---|---|
| Insertion sort | sorted | reverse | yes | |
| Merge sort | yes | |||
| Binary search | iterative | — |
- Insertion sort worst case: shifts . Shifts = number of inversions.
- Merging lists of sizes and : at most comparisons.
Loops
Details: Topic 5
| Pattern | Θ |
|---|---|
| independent nested | |
j ← 1 to i inside i ← 1 to n | (≈ ) |
| counter doubles / halves | |
| halving outer, inner does work | |
header for i ← 1 to n runs | times |
Asymptotics
Details: Topic 6
- : with for all
- : with for all
- : both, i.e.
- Disprove : assume exist, derive constant, contradiction.
Recurrences
Details: Topic 8
For : level has nodes of size , there are levels, and the leaves number .
| Recurrence | Θ |
|---|---|