Disjoint-Set Data Structure (Union-Find) | Fast Subset Checking
Visit Our Website: https://interviewpen.com/?utm_campaig... Join Our Discord: / discord Join Our Newsletter - The Blueprint: https://theblueprint.dev/subscribe Like & Subscribe: / @interviewpen This is an example of a full video available on interviewpen.com. Check out our website to find more premium content like this! Problem Statement: A [disjoint-set data structure](https://en.wikipedia.org/wiki/Disjoin...) (also called a “union-find” data structure), stores elements of a [set](https://en.wikipedia.org/wiki/Set_(ab...) as a series of trees (a “disjoint set [forest](https://en.wikipedia.org/wiki/Tree_(g...) representing disjoint subsets. Terms/Facts The disjoint-set structure is a series of directed trees (with all nodes pointing towards the root). Each directed tree represents a subset. Each node represents an item in a subset. The root node of any given subset tree is called the *representative* node and is symbolized by `repr(x)` (”the representative node of the subset `x` is contained in). If `repr(x) == repr(y)` then `x` & `y` are in the same subset (the same tree). The root node loops back to point to itself as its parent (forming a closed loop). The disjoint-set structure primes us for fast computation over 2 key operations: `FindRepr(x)` & `Union(x, y)`. Though the structure has 3 operations as follows: `MakeSet(x)`: Create a new subset with a single item with value `x` `FindRepr(x)`: Find the representative node for the subset containing `x` (this primes us for quickly seeing if `x` & `y` are in the same subset) `Union(x, y)`: Merge the subset containing `x` with the subset containing `y` (if `x` & `y` are in the same subset then no action is necessary) *Applications* *[Kruskal’s Algorithm](https://en.wikipedia.org/wiki/Kruskal... A disjoint-set data structure allows us to quickly check if adding a candidate edge will create a cycle. We aim to avoid connecting 2 nodes already in the same connected component. We only want to expand the Minimum Spanning Tree by connecting 2 disjoint components with the next cheapest edge (the algorithm’s goal). *References* [Notes](https://www.math.umd.edu/~immortal/CM...) (by Justin Wyss-Gallifent) Table of Contents: 0:00 - Introduction 1:18 - Trees Review 2:47 - Forests 3:48 - Visit interviewpen.com 4:08 - The Core Problem 06:18 - Kruskal’s Algorithm Review 08:01 - Disjoint-Set Operations 08:53 - Subset Representation 10:47 - Operations: MakeSet 11:56 - The Representative Node 12:59 - What Are Subsets in Trees? 13:30 - Operations: FindRepr (unoptimized) 14:55 - FindRepr Worst Case 15:24 - Operations: Union (unoptimized) 17:32 - Optimizing Operations 19:22 - Path Compression 21:49 - Weighted Union 25:01 - Complexities 28:00 - Closing Socials: Twitter: / interviewpen Twitter (The Blueprint): / theblueprintdev LinkedIn: / interviewpen Website: https://interviewpen.com/?utm_campaig...

Union Find Visually Explained

1.12 Disjoint Sets Data Structure - Weighted Union and Collapsing Find

Transformers from Scratch (Part 1): Tokenization, BPE, & Embeddings

Data Structures Explained for Beginners - How I Wish I was Taught

Why is Comparison Sorting Ω(n*log(n))? | Asymptotic Bounding & Time Complexity

The Strange Math That Predicts (Almost) Anything

System Design for Twitter (Timeline, Live Updates, Tweeting) | System Design Interview Prep

Turing Award Winner: Disagreeing with Google, Postgres, Future Problems | Mike Stonebraker

Disjoint Sets using union by rank and path compression Graph Algorithm

Disjoint Set | UNION and FIND

Disjoint Sets & Union Find Algorithm Simply Explained

But what is a neural network? | Deep learning chapter 1

Shorten Unix Path | Stacks and Strings

If You Have A Bad Memory, I’ll Help You Fix It In 28 Minutes

An Animated Introduction to the Union Find (Disjoint Set)

G-46. Disjoint Set | Union by Rank | Union by Size | Path Compression

The Insane Genius of a Formula 1 Gearbox

Understanding B-Trees: The Data Structure Behind Modern Databases

Disjoint set UNION by RANK and Path Compression

