VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 14: Greedy and intervals

Lesson 14.1 of 6 in this module Unrolled Pro

Greedy choices and how to prove them

A greedy algorithm makes the locally best choice at each step and never reconsiders. On a running example, ordering jobs on one GPU to minimise their average finishing time: from trying every order (n!), to sorting by duration (O(n log n)), with an exchange-argument proof of why it's optimal. Then the two standard proofs (exchange argument and greedy-stays-ahead), how to catch a wrong greedy by testing it against brute force, a greedy that fails (coins), and how weights and deadlines change the rule or rule greedy out.

about 10 min 3 Python examples 2 quick checks

The question this module answers: when can you commit to the choice that looks best right now, and never look back? Dynamic programming (module 12) considers every choice at every step and keeps the best. A greedy algorithm picks one choice by a simple rule (shortest first, earliest end first, farthest reach first) and moves on. When it works it's usually a sort plus a single pass, O(n log n). When it doesn't, it's silently wrong, which is why every greedy needs a proof or, at minimum, a brute-force test.

ML context.

  • Scheduling and serving: processing short requests first minimises average latency (this lesson's running example); packing jobs onto GPUs and merging time ranges (lessons 14.2–14.6).
  • Decoding: greedy decoding picks the most likely token at each step; beam search exists because that greedy isn't optimal for the whole sequence.
  • Feature and model selection: forward selection adds the single best feature at each step, a greedy with no optimality guarantee in general.
  • Compression: Huffman coding, which builds optimal prefix codes by repeatedly merging the two rarest symbols.

1. The running problem: order jobs to minimise average finishing time

Task: n jobs must run one at a time on one GPU. Job i takes d[i] seconds. A job's completion time is when it finishes. Choose an order that minimises the sum (equivalently the average) of completion times.

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Greedy choices and how to prove them"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee