Union Find Visualizer

Create disjoint sets, run union and find operations, inspect parent pointers, and see how path compression flattens connected components.

Nodes
6
Components
6
Largest
1
Max rank
0

Node input

Manual operation

Operation script

Disjoint set diagram

Sample disjoint sets loaded. Run union, find, or connected checks.

Root Path Compressed
Union find parent pointer diagramUnion find diagram with 6 nodes and 6 components.Ap=Arank 0Bp=Brank 0Cp=Crank 0Dp=Drank 0Ep=Erank 0Fp=Frank 0

Parent table

NodeParentRootRank
AAA0
BBB0
CCC0
DDD0
EEE0
FFF0

Components

Root A
A
Root B
B
Root C
C
Root D
D
Root E
E
Root F
F

Operation log

Sample disjoint sets loaded. Run union, find, or connected checks.

What is a Union Find Visualizer?

A union find visualizer shows how disjoint set union keeps track of connected components. Each node has a parent pointer. The root of a set represents the component.

Union find is common in graph connectivity, Kruskal’s minimum spanning tree algorithm, cycle detection, network grouping, and coding interview problems.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this union find visualizer

  • Create nodes such as A B C D E F.
  • Run union A B to merge two sets.
  • Run find A to find the root of a node.
  • Run connected A C to check whether two nodes share the same root.
  • Toggle path compression to see parent pointers flatten after find operations.

The diagram shows each node, its parent pointer, rank, and current component root.

Union find and graph connectivity

Union find answers whether two nodes belong to the same connected component. It does not traverse a graph edge by edge like BFS or DFS. Instead, it merges components as edges are processed.

To compare both approaches, use this page with the Graph BFS DFS Visualizer. For a direct minimum spanning tree use case, try the Kruskal Algorithm Visualizer. For weighted graph shortest paths, use the Dijkstra Algorithm Visualizer.

Frequently Asked Questions

What is disjoint set union?
Disjoint set union is another name for union find. It stores separate sets and supports find and union operations.
What does find do?
Find follows parent pointers from a node to the root of its component.
What does union do?
Union merges the two components that contain the selected nodes.
What is path compression?
Path compression updates nodes on a find path so they point directly to the root, which makes future operations faster.

Related tools