Skip to content
Optimal Lab

DSA · interactive

Topological sort: an order that respects dependencies

Courses with prerequisites, build steps, package installs: what can you do first? Count each item's unmet prerequisites, start with the ones at zero, and unlock the rest as you go.

Intro0Data1Web1Algo1APIs2Systems2

Ready queue: Intro

Order: —

Count prerequisites for each course. Courses with 0 can start: Intro.

Prerequisites

step 1 of 8
  1. 1

    For each node, count how many prerequisites point at it. That's the small number on each box.

    indegree[v]++ for each edge u → v

  2. 2

  3. 3

  4. 4

In production

Tools and technologies

Every build and package tool sorts dependencies.

Not tied to one language — use these names when you search docs or design a system.