← Algorithm Design learning path
Algorithm Design · Module 3 of 10

Greedy algorithms

Make the locally best choice at each step.

📖 Key ideas

  1. Greedy algorithms pick the best immediate option.
  2. Work when the problem has greedy-choice property and optimal substructure.
  3. Examples: activity selection, Huffman coding, Kruskal, Prim, Dijkstra.
  4. Fractional knapsack is greedy; 0/1 knapsack is not.
  5. Prove correctness with exchange arguments.
💡 Real-life example: Greedy is eating the best dish at each buffet counter; it works only if each local best leads to the best meal.
Greedy choiceBest local decision
Optimal substructureOptimal solution built from optimal subproblems
Huffman codingGreedy compression
Activity selectionPick max non-overlapping intervals