Algorithm Design

Greedy Algorithms: Scheduling, Caching, and Shortest Paths

17:24

Plays from YouTube. Watch on YouTube

How can an algorithm make one decision at a time and still guarantee the best possible result?

Meet Greedy Algorithms: where simple local choices, clever invariants, and rigorous proofs come together.

We start with interval scheduling. Why does choosing the earliest starting job fail, while choosing the earliest finishing compatible job produces an optimal schedule? We work through an actual set of intervals and the exchange argument that proves the choice is safe.

Next, we tackle deadlines and maximum lateness. We compare tempting but incorrect scheduling rules, then show why processing jobs in earliest-deadline order works, using an adjacent-swap proof.

Then we explore optimal offline caching. When memory is full, which item should we evict? We trace a concrete request sequence and show why removing the item needed farthest in the future minimizes cache misses when the future is known.

Finally, we build Dijkstra's shortest-path algorithm from tentative distances, settled vertices, priority queues, and relaxation. We reconstruct an actual path and explain why nonnegative edge weights are essential to the correctness proof.

The big idea: A greedy algorithm is not just a fast guess. It works when we can prove that each local decision preserves a path to a globally optimal solution.

Algorithms explained visually, one concept at a time.