Cheat sheets

ALG-13Cheat sheet1 pageIn a paid pack

Greedy: Activities, Knapsack, Jobs

The greedy-choice property and optimal substructure, with the exchange argument used to prove a greedy rule; activity selection by earliest finish with a full trace and the rules that fail (shortest first, earliest start) shown by counterexamples; fractional knapsack by value per weight and why the same rule fails for 0/1 knapsack; job sequencing with deadlines and unit times using the latest free slot; coin systems where greedy change is and is not optimal. Every greedy answer is compared with brute force by script.

ALG-14Cheat sheet1 pageIn a paid pack

Huffman Coding and Optimal Merge Pattern

Prefix-free codes and why decoding is unambiguous; Huffman's algorithm with a min-priority queue, traced on six symbols with the resulting tree, codes, weighted cost and average code length, compared with a fixed 3-bit code and checked against every valid set of code lengths; properties of Huffman trees (full, Kraft equality, the two rarest symbols as deepest siblings, longest possible code); tie-breaking and why the cost never changes; encoding a word; the optimal merge pattern for sorted files with its record-move total.

Diagrams from ALG-14