Graphs

Problem shape

Intermediate
A
B
C
D
E
Core idea

Sort edges by weight and add edges that connect different components.

Step 1 / 5
Problem shape
Current lesson

Kruskal MST Lab

Graphs Intermediate

Kruskal MST

Welcome to the Kruskal MST algorithm lab. Sort edges by weight and add edges that connect different components. Use it when: Use for minimum spanning tree on sparse graphs. The time complexity is O(E log E), and the space complexity is O(V). The pseudocode is: sort edges by weight for edge in edges if find(u) != find(v) take edge union(u, v) As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(E log E)

Space

O(V)

Pseudocode

sort edges by weight
for edge in edges
  if find(u) != find(v)
    take edge
    union(u, v)
Open deeper structure lesson
1.0x