Skip to content
Sahithyan's S2
1
Sahithyan's S2 — Data Structures and Algorithms

Union Find

Aka. Disjoint Set Union (DSU). Keeps track of a partition of a set into disjoint subsets.

Used in Kruskal’s algorithm, connected components in a graph, cycle detection in undirected graphs, dynamic connectivity problems.

Determines which subset a particular element belongs to. This can be used to check if two elements are in the same subset.

Joins two subsets into a single subset. This is used to merge groups.

Typically implemented using two techniques to optimize its operations:

During the Find operation, the structure flattens the tree by making every node point directly to the root. This reduces the time complexity of future operations.

During the Union operation, the smaller tree is attached under the root of the larger tree. This keeps the tree shallow, improving efficiency.