Connected Components — interactive algorithm visualization

Medium · Union-Find · time O(E·α(N)) · space O(N)

Merge elements into disjoint sets and count the roots. Near-constant per operation with path compression.

Example input: n = 6, edges = [[0,1],[1,2],[3,4]]

Step through a verified execution trace - every step shows the real state, the invariant that keeps the algorithm correct, and asks you to predict what happens next.

Solve Connected Components in the editor · All 16 visualizations

Previous: Breadth-First Search · Next: Implement Trie