Authored by Tony Feng
Created on April 7th, 2022
Last Modified on April 9th, 2022
Understanding Union Find
Intro
- A disjoint-set data structure keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets.
- A union-find algorithm performs union and find operation on those subsets.
- Union-Find Algorithm can be used to check whether an undirected graph contains cycle or not.
Union & Find
- Find
- It determines in which subset a particular element is in and returns the representative of that particular set.
- Union
- It merges two different subsets into a single subset, and the representative of one set becomes representative of another.
Template
Common Union Find
|
|
Union Find Improvement
|
|
Examples
Leetcode 200 Number of Islands
|
|
Reference
- 手把手带你刷Leetcode力扣 - 并查集 Union Find
- 手把手带你刷Leetcode力扣 - 并查集优化 Union Find Optimization
- 手把手带你刷Leetcode力扣 - Leetcode 200
- Disjoint Set (Or Union-Find)
- Disjoint–Set Data Structure (Union–Find Algorithm)