DATA STRUCTURES/Student Engineering Notebook
Page 10·notes
HASHING, COLLISION DYNAMICS & DISJOINT SETS—~32 MIN READ

Disjoint Set Union (DSU): Union by Rank & Path Compression

“Partition representation, tree rank heuristics, path compression mechanics, and the inverse Ackermann bound O(alpha(n)).”

1.The Disjoint Set ADT & Representation

A Disjoint Set Union (DSU) data structure maintains a collection S = {S_1, S_2, ..., S_k} of disjoint dynamic sets.

Each set is identified by a canonical representative (the root of a tree).

Core Operations:

1. Make-Set(x): Initializes {x}.

2. Find-Set(x): Returns the representative of the set containing x.

3. Union(x, y): Merges the sets containing x and y.

2.The Two Synergistic Optimizations

1. Union by Rank:

Each node stores a rank (an upper bound on its height).

When unioning two sets, make the root with smaller rank point to the root with larger rank. If both ranks are equal, pick either root and increment its rank by 1.

This guarantees that tree depth never exceeds O(log n).

2. Path Compression:

During Find-Set(x), update the parent pointer of every node visited along the path to point directly to the root.

Combined Complexity:

Combining Union by Rank with Path Compression yields an amortized time of O(alpha(n)) per operation, where alpha(n) is the extremely slow-growing Inverse Ackermann function.

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATIONOriginal Practice Problem · Modeled on GATE Pattern (2 Marks)

3. Worked Problem: Rank Invariant & Union Sequence

⚠️ Pitfall Warning:

Rank increases if and only if both roots being unioned have identical rank.

Problem: Elements {1, 2, 3, 4, 5, 6, 7, 8} are initialized using Make-Set (rank 0 for all). The following sequence of Union operations is performed using Union by Rank: Union(1, 2), Union(3, 4), Union(5, 6), Union(7, 8), Union(1, 3), Union(5, 7), Union(1, 5). What is the final rank of the root node?

Step 1: Pairwise unions at rank 0:

- Union(1, 2): rank(1)=0, rank(2)=0. Equal! Root = 1, rank(1) = 0 + 1 = 1.

- Union(3, 4): rank(3)=0, rank(4)=0. Equal! Root = 3, rank(3) = 1.

- Union(5, 6): rank(5)=0, rank(6)=0. Equal! Root = 5, rank(5) = 1.

- Union(7, 8): rank(7)=0, rank(8)=0. Equal! Root = 7, rank(7) = 1.

Step 2: Second-level unions at rank 1:

- Union(1, 3): rank(1)=1, rank(3)=1. Equal! Root = 1, rank(1) = 1 + 1 = 2.

- Union(5, 7): rank(5)=1, rank(7)=1. Equal! Root = 5, rank(5) = 1 + 1 = 2.

Step 3: Final union at rank 2:

- Union(1, 5): rank(1)=2, rank(5)=2. Equal! Root = 1, rank(1) = 2 + 1 = 3.

Final Answer: The final root has a rank of 3.

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Introduction to Algorithms (4th Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Abdul Bari · Data Structures & Algorithms↗Instructor: Abdul Bari · Covers: Trees, graphs, hashing, sorting — with visual algorithm animations

Visual thinkers who want to see each algorithm step animated clearly.

Open YouTube↗
Gate Smashers · Data Structures Full Course↗Instructor: Varun Singla · Covers: Arrays, linked lists, trees, BST, AVL, heaps, hashing — GATE numericals

GATE-targeted coverage with step-by-step GATE PYQ walkthroughs.

Open YouTube↗