Graphs

Problem shape

Intermediate
A
B
C
D
E
Core idea

Order directed acyclic graph nodes so prerequisites come first.

Step 1 / 5
Problem shape
Current lesson

Topological Sort Lab

Graphs Intermediate

Topological Sort

Welcome to the Topological Sort algorithm lab. Order directed acyclic graph nodes so prerequisites come first. Use it when: Use for build systems, course scheduling, and dependency graphs. The time complexity is O(V + E), and the space complexity is O(V). The pseudocode is: compute indegree push nodes with indegree 0 while queue not empty node = pop append node reduce neighbors indegree As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(V + E)

Space

O(V)

Pseudocode

compute indegree
push nodes with indegree 0
while queue not empty
  node = pop
  append node
  reduce neighbors indegree
Open deeper structure lesson
1.0x