Resource · Guide or article
Disjoint Set
Introduces union-find, which tracks elements split into non-overlapping groups, and notes its role in Kruskal's minimum spanning tree algorithm.
Reviewed
Open the original: Disjoint Set (opens the original site in a new tab)Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
Read this in other languages: Русский, Português, Українська Disjoint-set data structure (also called a union–find data structure or merge–find set) is a data structure that tracks a set of elements partitioned into a number of disjoint (non-overlapping) subsets. It provides near-constant-time operations (bounded by the inverse Ackermann function) to add new sets, to merge existing sets, and to determine whether elements are in the same set. In addition to many other uses (see the Applications section), disjoint-sets play a key role in Kruskal's algorithm for finding the minimum spanning tree of a graph. After some operations of Union, some sets are grouped together.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- States near-constant-time make-set, union and find, bounded by the inverse Ackermann function
- Before and after diagrams of eight singletons being merged
- Points to a minimal DisjointSetAdhoc.js meant for pasting during a coding interview where the interviewer allows it
How to use it
PrepKit study advice, not a claim made by the source.
Write union-find with path compression and union by rank from memory, then use it to count connected components in a small edge list.
Scope and limitations
Path compression and union by rank are not explained on the page. The code lives in the folder's JavaScript files, and the theory is in the Wikipedia and YouTube links.
Access and format
README on GitHub, trekhleb/javascript-algorithms (MIT), with Russian, Portuguese and Ukrainian translations linked. English, free.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/data-structures/disjoint-set/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.