Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Topological Sort Lab
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
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 1.0x