VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.7 of 16 in this module Unrolled Pro

Course Schedule II

Return an order to take all courses so every prerequisite comes first: a topological sort, or an empty list if a cycle makes it impossible. From trying orders and checking them (n! candidates), to repeatedly scanning for a ready course (O(V · E)), to Kahn's algorithm (O(V + E)) and the reverse of DFS finishing order. Then the lexicographically smallest order with a heap, the minimum number of semesters when independent courses run in parallel, and scheduling pipeline stages level by level.

about 10 min 3 Python examples 2 quick checks

Problem. n courses, and pairs [a, b] meaning b must be taken before a. Return any order of all courses that respects every prerequisite, or [] if none exists.

text
n = 4, prerequisites = [[1, 0], [2, 0], [3, 1], [3, 2]]   →   [0, 1, 2, 3]   or   [0, 2, 1, 3]
n = 2, prerequisites = [[1, 0], [0, 1]]                     →   []

Such an order is a topological order of the graph with edges b → a. Lesson 11.6 checked whether one exists; here we produce it, and look at which order to produce when several are valid.

ML context. Running a pipeline means executing its tasks in a topological order: preprocessing before training, training before evaluation. Independent tasks can run in parallel, and the minimum number of parallel "waves" is the length of the longest dependency chain (Change B), which bounds the wall-clock time of a pipeline even with unlimited workers.


1. Step 1: Clarify

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

Unlock "Course Schedule II"

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