Dynamic Union Set (Data Structure & Algorithm)
- is a data structure that supports dynamic union operations over a set of elements
Dynamic Union Set - Operations
|
Operation |
Description |
|---|---|
|
initialize(n) |
initializes data structure with n elements |
|
void union(p, q) |
connects element p and q |
|
boolean connected(p, q) |
returns whether elements p and q are connected |
|
int find(p) |
returns the component identifier of element p |
|
int count() |
returns the number of components in the data structure |
Dynamic Union Set - Algorithm Types
given 𝑀 union operations over a set of size 𝑁
|
Algorithm Type |
Pseudo Code |
initialize(n) |
union(p, q) |
connected(p, q) |
|---|---|---|---|---|
|
Quick Find (QF) |
|
𝑁 |
𝑂(𝑁) |
𝑂(1) |
|
Quick Union (QU) |
|
𝑁 |
𝑂(𝑁) |
𝑂(𝑁) |
|
Weighted QU |
|
𝑁 |
𝑂(𝑙𝑔𝑁) |
𝑂(𝑙𝑔𝑁) |
|
QU + Path Compression |
|
𝑁 | ||
|
Weight QU + Path Compression |
|
𝑁 |