How to recognise
an optimum where one choice at each step always looks safe: jump as far as you can, take the meeting that ends first.
How to solve problems like this
- Name the choice you make at each step: the farthest jump, the earliest end, the cheapest option.
- Check that it is safe: swapping it for any other choice never gives a better answer. If it can, use dynamic programming instead.
- Sort first if the choice depends on order: by end time, by deadline, by size.
- Make one pass with a single running value, and stop as soon as the answer is known.
Where it's used
- Compression. The Huffman code in zip, gzip and PNG is built greedily: the two rarest symbols are glued into one, again and again. Common symbols get short codes, rare ones long codes.
- Routing. Routers running OSPF find shortest paths with Dijkstra's algorithm: each time they settle the nearest point not yet settled and never revisit it.