Union Find Introduction
Introduction to the Disjoint Set (Union find) data structure
Related Videos:
Union find intro: https://www.youtube.com/watch?v=ibjEGG7ylHk
Union find kruskal's algorithm: https://www.youtube.com/watch?v=JZBQLXgSGfs
Union find union and find: https://www.youtube.com/watch?v=0jNmHPfA_yE
Union find path compression: https://www.youtube.com/watch?v=VHRhJWacxis
Union find code: https://www.youtube.com/watch?v=KbFlZYCpONw
Data Structures Source Code:
https://github.com/williamfiset/algorithms
====================================
Practicing for interviews? I have used, and recommend `Cracking the Coding Interview` which got me a job at Google. Link on Amazon: https://amzn.to/3cvMof5
A lot of the content on this channel is inspired by the book `Competitive Programming` by Steven Halim which I frequently use as a resource and reference. Link on Amazon: https://amzn.to/3wC2nix ===================================
Practicing for interviews? I have used, and recommend `Cracking the Coding Interview` which got me a job at Google. Link on Amazon: https://amzn.to/3cvMof5
A lot of the content on this channel is inspired by the book `Competitive Programming` by Steven Halim which I frequently use as a resource and reference. Link on Amazon: https://amzn.to/3wC2nix
What You'll Learn
The video introduces the Union Find data structure, also known as the Disjoint Set, and its applications in various algorithms such as Kruskal's minimum spanning tree algorithm. It covers the find and union operations, path compression, and the complexity of the Union Find data structure.
Full Transcript
all right time to talk about the union find also sometimes called the disjoint set this is my favorite data structure so let's get started so an outline of things we'll be covering about the union find first I'll be going over a motivating example with magnets uh just to illustrate how useful the union find can be then we'll go over a classic example of an algorithm which uses the and find specifically crucial's minimum spanning tree algorithm which is very elegant and you'll see why it needs the union find to get the complexity it has then we're going to go into some detail concerning the find and the union operations the two core operations the union find uses and finally we'll have a look at path compression um what gives us the really nice amortized constant time uh the union fine provides okay let's dive into uh some discussion examples concerning the union find so what what is a union find so the union find is a data structure that tracks Elements which are split into one or more uh disjoint sets and the union find has two primary operations find and Union what find does is given an element the union finds will tell you what group that element belongs to and Union merges to groups together so if we have this example with magnets suppose all these gray rectangles you see on the screen are magnets and also suppose that the magnets have a very high attraction to each other meaning they want to merge together to form some sort of configuration so if I label all the magnets and give them numbers and we start merging the magnets of the highest attraction first we're going to merge six and8 together since they're the closest so in our Union find we would say Union 6 and 8 and when we do a lookup on to find out which groups six and8 belong to they would belong to the blue group uh now perhaps two three and three and four are highly attracted to each other so they would form a group so they would form the yellow group and perhaps 10 13 and 14 would also form a group and this keeps on going and we unify magnets into groups and perhaps we merge some magnets onto already existing groups so we uh unify um a gray magnet which is just a magnet in its own group to an already existing group but also we can unify uh groups of magnets which are different colors and then we assign it an arbitrary color so uh blue so suddenly everything in the yellow group went into uh the blue group and now when we would do a look up in our Union find to determine which group uh say two three or four are now we would say ah you're in the blue group and the union fine does all this merging and finding in a very efficient manner which is why it's so handy to have around I'm not explaining currently how that works we'll get into that in the later video this is just a motivating example so where are other places that the union find is used well we we well we see the union find again in cul's minimum spanning tree algorithm um in another problem called grid percolation where there's a bunch of uh dots on a grid and we're trying to see if there's a path from the bottom of the grid to the top of the Grid or vice versa then the union find lets us do that efficiently by uh merging together paths also uh s similar kind of problem in network connectivity are two vertices and a graph connected to each other through a series of edges and also perhaps in some more advanced examples like the least common ancestor in a tree and also in image processing so what kind of complexity can we attribute to the union find uh the complexity is excellent so its construction is linear time which isn't actually bad at all then the union find get component and check if connected operations all happened in what's called amortized constant time so almost constant time although not quite constant time and finally uh count components well we can determine how many components or in our magnet examples how many different groups of magnets we have and we can do that in constant time which is really really great so in the next video we're going to have a look at kill's minimum spending tree algorithm and how it uses the union find so guys thank you for watching and I will catch you then
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from WilliamFiset · WilliamFiset · 45 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
▶
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
JES Image Manipulation - 2 - Installation
WilliamFiset
JES Image Manipulation - 3 - User Interface
WilliamFiset
JES Image Manipulation - 5 - Negative
WilliamFiset
JES Image Manipulation - 6 - Black & White
WilliamFiset
JES Image Manipulation - 4 - Grayscale
WilliamFiset
JES Image Manipulation - 8 - Blur
WilliamFiset
JES Image Manipulation - 7 - Edge Detection
WilliamFiset
JES Image Manipulation - 9 - Blend
WilliamFiset
JES Image Manipulation - 10 - Matte
WilliamFiset
JES Image Manipulation - 13 - Rotate90
WilliamFiset
JES Image Manipulation - 12 - Mirroring Picture
WilliamFiset
JES Image Manipulation - 11 - Crop Image
WilliamFiset
JES Image Manipulation - 14 - Stretch picture
WilliamFiset
Java Fractal Explorer [6/8]
WilliamFiset
Java Fractal Explorer [4/8]
WilliamFiset
Java Fractal Explorer [8/8]
WilliamFiset
Java Fractal Explorer [5/8]
WilliamFiset
Java Fractal Explorer [2/8]
WilliamFiset
Java Fractal Explorer [7/8]
WilliamFiset
Java Fractal Explorer [1/8]
WilliamFiset
Java Fractal Explorer [3/8]
WilliamFiset
Introduction [Programming Competition Problems]
WilliamFiset
String Manipulation 1 [Programming Competition Problems]
WilliamFiset
String Manipulation 2 [Programming Competition Problems]
WilliamFiset
Graph Theory 1 [Programming Competition Problems]
WilliamFiset
Logic 1 [Programming Competition Problems]
WilliamFiset
Grid Problems 1 [Programming Competition Problems]
WilliamFiset
Dynamic Programming 1 [Programming Competition Problems]
WilliamFiset
Introduction to Big-O
WilliamFiset
Dynamic and Static Arrays
WilliamFiset
Dynamic Array Code
WilliamFiset
Linked Lists Introduction
WilliamFiset
Doubly Linked List Code
WilliamFiset
Stack Introduction
WilliamFiset
Stack Implementation
WilliamFiset
Stack Code
WilliamFiset
Queue Introduction
WilliamFiset
Queue Implementation
WilliamFiset
Queue Code
WilliamFiset
Priority Queue Introduction
WilliamFiset
Priority Queue Min Heaps and Max Heaps
WilliamFiset
Priority Queue Inserting Elements
WilliamFiset
Priority Queue Removing Elements
WilliamFiset
Priority Queue Code
WilliamFiset
Union Find Introduction
WilliamFiset
Union Find Kruskal's Algorithm
WilliamFiset
Union Find - Union and Find Operations
WilliamFiset
Union Find Path Compression
WilliamFiset
Union Find Code
WilliamFiset
Binary Search Tree Introduction
WilliamFiset
Binary Search Tree Insertion
WilliamFiset
Binary Search Tree Removal
WilliamFiset
Binary Search Tree Traversals
WilliamFiset
Binary Search Tree Code
WilliamFiset
Fenwick Tree range queries
WilliamFiset
Fenwick Tree point updates
WilliamFiset
Fenwick Tree construction
WilliamFiset
Fenwick tree source code
WilliamFiset
Hash table hash function
WilliamFiset
Hash table separate chaining
WilliamFiset
More on: Graph Algorithms
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Bloom Filters, Explained Properly
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Medium · Python
🎓
Tutor Explanation
DeepCamp AI