Oleksii Trekhleb | Javascript algorithms (Disjoint set)
This is a series of books diving deep into the core mechanisms of the JavaScript language.
· 1 phút đọc.
![nhavantuonglai This is a series of books diving deep into the core mechanisms of the JavaScript language.](https://data.nhavantuonglai.com/image/illustrations/cover-nhavantuonglai-com-0523.jpg)
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.
MakeSet creates 8 singletons.
After some operations of Union, some sets are grouped together.
Implementation
The minimalistic (ad hoc) version of a DisjointSet (or a UnionFind) data structure that doesn’t have external dependencies and that is easy to copy-paste and use during the coding interview if allowed by the interviewer (since many data structures in JS are missing).
![nhavantuonglai nhavantuonglai](https://data.nhavantuonglai.com/image/illustrations/cover-nhavantuonglai-com-0127.jpg)