Union Find Introduction

WilliamFiset · Beginner ·⚡ Algorithms & Data Structures ·9y ago
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 JES Image Manipulation - 2 - Installation
JES Image Manipulation - 2 - Installation
WilliamFiset
2 JES Image Manipulation - 3 - User Interface
JES Image Manipulation - 3 - User Interface
WilliamFiset
3 JES Image Manipulation - 5 - Negative
JES Image Manipulation - 5 - Negative
WilliamFiset
4 JES Image Manipulation - 6 - Black & White
JES Image Manipulation - 6 - Black & White
WilliamFiset
5 JES Image Manipulation - 4 - Grayscale
JES Image Manipulation - 4 - Grayscale
WilliamFiset
6 JES Image Manipulation - 8 - Blur
JES Image Manipulation - 8 - Blur
WilliamFiset
7 JES Image Manipulation - 7 - Edge Detection
JES Image Manipulation - 7 - Edge Detection
WilliamFiset
8 JES Image Manipulation - 9 - Blend
JES Image Manipulation - 9 - Blend
WilliamFiset
9 JES Image Manipulation - 10 - Matte
JES Image Manipulation - 10 - Matte
WilliamFiset
10 JES Image Manipulation - 13 - Rotate90
JES Image Manipulation - 13 - Rotate90
WilliamFiset
11 JES Image Manipulation - 12 - Mirroring Picture
JES Image Manipulation - 12 - Mirroring Picture
WilliamFiset
12 JES Image Manipulation - 11  - Crop Image
JES Image Manipulation - 11 - Crop Image
WilliamFiset
13 JES Image Manipulation - 14 - Stretch picture
JES Image Manipulation - 14 - Stretch picture
WilliamFiset
14 Java Fractal Explorer [6/8]
Java Fractal Explorer [6/8]
WilliamFiset
15 Java Fractal Explorer [4/8]
Java Fractal Explorer [4/8]
WilliamFiset
16 Java Fractal Explorer [8/8]
Java Fractal Explorer [8/8]
WilliamFiset
17 Java Fractal Explorer [5/8]
Java Fractal Explorer [5/8]
WilliamFiset
18 Java Fractal Explorer [2/8]
Java Fractal Explorer [2/8]
WilliamFiset
19 Java Fractal Explorer [7/8]
Java Fractal Explorer [7/8]
WilliamFiset
20 Java Fractal Explorer [1/8]
Java Fractal Explorer [1/8]
WilliamFiset
21 Java Fractal Explorer [3/8]
Java Fractal Explorer [3/8]
WilliamFiset
22 Introduction [Programming Competition Problems]
Introduction [Programming Competition Problems]
WilliamFiset
23 String Manipulation 1 [Programming Competition Problems]
String Manipulation 1 [Programming Competition Problems]
WilliamFiset
24 String Manipulation 2 [Programming Competition Problems]
String Manipulation 2 [Programming Competition Problems]
WilliamFiset
25 Graph Theory 1 [Programming Competition Problems]
Graph Theory 1 [Programming Competition Problems]
WilliamFiset
26 Logic 1 [Programming Competition Problems]
Logic 1 [Programming Competition Problems]
WilliamFiset
27 Grid Problems 1 [Programming Competition Problems]
Grid Problems 1 [Programming Competition Problems]
WilliamFiset
28 Dynamic Programming 1 [Programming Competition Problems]
Dynamic Programming 1 [Programming Competition Problems]
WilliamFiset
29 Introduction to Big-O
Introduction to Big-O
WilliamFiset
30 Dynamic and Static Arrays
Dynamic and Static Arrays
WilliamFiset
31 Dynamic Array Code
Dynamic Array Code
WilliamFiset
32 Linked Lists Introduction
Linked Lists Introduction
WilliamFiset
33 Doubly Linked List Code
Doubly Linked List Code
WilliamFiset
34 Stack Introduction
Stack Introduction
WilliamFiset
35 Stack Implementation
Stack Implementation
WilliamFiset
36 Stack Code
Stack Code
WilliamFiset
37 Queue Introduction
Queue Introduction
WilliamFiset
38 Queue Implementation
Queue Implementation
WilliamFiset
39 Queue Code
Queue Code
WilliamFiset
40 Priority Queue Introduction
Priority Queue Introduction
WilliamFiset
41 Priority Queue Min Heaps and Max Heaps
Priority Queue Min Heaps and Max Heaps
WilliamFiset
42 Priority Queue Inserting Elements
Priority Queue Inserting Elements
WilliamFiset
43 Priority Queue Removing Elements
Priority Queue Removing Elements
WilliamFiset
44 Priority Queue Code
Priority Queue Code
WilliamFiset
Union Find Introduction
Union Find Introduction
WilliamFiset
46 Union Find Kruskal's Algorithm
Union Find Kruskal's Algorithm
WilliamFiset
47 Union Find - Union and Find Operations
Union Find - Union and Find Operations
WilliamFiset
48 Union Find Path Compression
Union Find Path Compression
WilliamFiset
49 Union Find Code
Union Find Code
WilliamFiset
50 Binary Search Tree Introduction
Binary Search Tree Introduction
WilliamFiset
51 Binary Search Tree Insertion
Binary Search Tree Insertion
WilliamFiset
52 Binary Search Tree Removal
Binary Search Tree Removal
WilliamFiset
53 Binary Search Tree Traversals
Binary Search Tree Traversals
WilliamFiset
54 Binary Search Tree Code
Binary Search Tree Code
WilliamFiset
55 Fenwick Tree range queries
Fenwick Tree range queries
WilliamFiset
56 Fenwick Tree point updates
Fenwick Tree point updates
WilliamFiset
57 Fenwick Tree construction
Fenwick Tree construction
WilliamFiset
58 Fenwick tree source code
Fenwick tree source code
WilliamFiset
59 Hash table hash function
Hash table hash function
WilliamFiset
60 Hash table separate chaining
Hash table separate chaining
WilliamFiset

The Union Find data structure is a powerful tool for solving graph problems and tracking disjoint sets. It has two primary operations, find and union, and provides excellent time complexity. This video introduces the basics of Union Find and its applications.

Key Takeaways
  1. Define the Union Find data structure and its operations
  2. Understand the motivating example with magnets
  3. Learn about Kruskal's minimum spanning tree algorithm and its use of Union Find
  4. Study the find and union operations in detail
  5. Explore path compression and its effect on time complexity
💡 The Union Find data structure provides amortized constant time complexity for its operations, making it a highly efficient tool for solving graph problems.

Related AI Lessons

Bloom Filters, Explained Properly
Learn how Bloom filters work and their benefits, including tiny memory and blazing speed, in exchange for potential false positives.
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Learn how prefix sums enable instant range queries in arrays, boosting performance in various applications
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
A simple math question can destroy a developer's interview, highlighting the importance of being prepared for unexpected questions
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Learn to remove duplicates from a sorted array using the two pointers technique, improving from brute force to optimized solutions
Medium · Python
Up next
Stump Grinder Carbide Wheel Grinds Hardwood To Chips
Innoforge Studio
Watch →