Тёмный
No video :(

Union Find Path Compression 

WilliamFiset
Подписаться 177 тыс.
Просмотров 119 тыс.
50% 1

Related Videos:
Union find intro: • Union Find Introduction
Union find kruskal's algorithm: • Union Find Kruskal's A...
Union find union and find: • Union Find - Union and...
Union find path compression: • Union Find Path Compre...
Union find code: • Union Find Code
Data Structures Source Code:
github.com/wil...
My website: www.williamfise... ===================================
Practicing for interviews? I have used, and recommend `Cracking the Coding Interview` which got me a job at Google. Link on Amazon: 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: amzn.to/3wC2nix

Опубликовано:

 

6 апр 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 56   
@vishalmishra7018
@vishalmishra7018 5 лет назад
Thank you for explaining these concepts so beautifully. Please keep posting new videos. Thank you so much.
@ErnestoEnriquez-du4jj
@ErnestoEnriquez-du4jj Год назад
Holy mother of clarity. Great explanation, bro.
@khadijahflowers5566
@khadijahflowers5566 6 лет назад
Just to be clear, path compression happens during a find operation AND union operations? Also, why didn't you also compress A and C to point to E?
@WilliamFiset-videos
@WilliamFiset-videos 6 лет назад
Q: "Just to be clear, path compression happens during a find operation AND union operations?" A: Yes! In fact, in the code implementation the union operation calls the find method which is where the path compression is done. Q: "why didn't you also compress A and C to point to E?" A: We lazily do path compression, so It only applies to the nodes which we unify.
@lamihh
@lamihh 4 года назад
this comment should be pinned
@Sulerhy
@Sulerhy Месяц назад
Thank you so much it is extremely helpful. One image's worth 1000 of words
@theawless
@theawless 3 года назад
All 4 videos on this topic are a gem!
@kevinpreston5260
@kevinpreston5260 6 лет назад
It seems it would be better to set the new root of a union as the root of the tree with the larger height so that the resulting tree has the smallest height possible. See union(H,F) @ 4:07.
@WilliamFiset-videos
@WilliamFiset-videos 6 лет назад
I did that setup at 4:07 intentionally to compare how beneficial path compression can be. You're correct in saying that as a heuristic you want to merge the smaller tree into the larger one. I've done imprical tests in the past and this has given me a performance boost.
@shijieru
@shijieru 5 лет назад
In around 4:11, for operation Union(A,C), I don't understand why the result is B points to C instead of B points to D?
@WilliamFiset-videos
@WilliamFiset-videos 5 лет назад
It could go eitherway, it does not matter as long as the components are unified.
@therealbnut
@therealbnut 23 дня назад
Hey, just wondering why at 3:22 you wouldn’t compress all the traversed nodes when finding F to point to G instead, creating a star topology. It seems like this wouldn’t require any more work and would be much more optimal. Sorry to bring this up after so long, haha.
@loloioi
@loloioi 5 лет назад
Hey William, I'm kind of confused approx @5:00 when you do the union(J,G). Why are you path compressing based on the new graph? The graph has yet to merge together. I think it would make sense if the graph you are merging into can be path compressed. For example, lets say you have H as root node w/ node I pointing to H, and j pointing to I. There is another directed graph where F is pointing to E. Example 1) Suppose you call union(F,H). Suppose E points to H. Then F should still point to E but E now points to H and H having it's original children nodes. F is not apart of H and you are calling find(F) which has E as its root. Example 2) Suppose you call union(F,I). Then, path compression should happen and I, J and E is pointing to H. Also, F is pointing to E still.
@klarisa1784
@klarisa1784 3 года назад
Exactly!!
@tranluuquoctuan4422
@tranluuquoctuan4422 Год назад
same doubt :v
@garceaalex7298
@garceaalex7298 4 года назад
At 4:09, after Union(H, F), why H points to E? H's group is larger.
@bishakhdutta8427
@bishakhdutta8427 3 года назад
it doesn't make a difference you can do it both ways
@bishakhdutta8427
@bishakhdutta8427 3 года назад
only condition is they should belong to the same group
@pedrobraga4944
@pedrobraga4944 Год назад
Great video! Just one doubt. I saw that people already asked why C and A are not connected to E, after compression, and you already answered, but still cant understand :(
@ayushijmusic
@ayushijmusic Год назад
Savior. Thanks for this amazing content ! :)
@arunkutube
@arunkutube Год назад
Love the way it's explained.
@t_min_o
@t_min_o 15 дней назад
COuld have explained more clearly as to how it is compressed in each step!
@thiagomelo2788
@thiagomelo2788 7 лет назад
Hi, William! Do you link some nodes like (C, D) and (E, F) (using different ways. It's just for this example or have some reason? Hi William! You link some nodes as (C, D) and (E, F) using different ways (left - > right and left < - right). A little different from the previous video. It's just for this example, or is there some special reason? Thanks, in advance!
@WilliamFiset-videos
@WilliamFiset-videos 7 лет назад
Hi Thiago, if you're referring to the first example that's just a hypothetical setup to illustrate path compression. The actual direction in which the nodes are linked together does not matter, your union find will still work correctly. However, from experience, if you merge the smaller group into the larger group you can get a mild performance boost.
@RohithMusic
@RohithMusic Год назад
At 3:24, should we also point A B C D E to G instead of F?
@hamza-chaudhry
@hamza-chaudhry 4 месяца назад
3:22 Would you not make E, D, C, B, A parents all G?
@Yan-rv8mi
@Yan-rv8mi 4 года назад
5:25 finding A or C at this point, still take more than one hop (in this case, 2 hops) since they're not directing pointing at E. Could you prove that such 2 hops in worst case? is it still constant time, or become linear time?
@victor2183
@victor2183 2 года назад
He had not enough space to represent all the nodes pointing to E around it that's why he didn't pointed A and C to it.
@adityasahu96
@adityasahu96 5 лет назад
brilliant and easily explained thhanks
@alanlybus4352
@alanlybus4352 3 года назад
Thank you! Great explanation.
@swordwaker7749
@swordwaker7749 5 лет назад
My version of union-find doesn't use this path compression method. My version makes the representative of each node union together and all nodes from the smaller group enter the larger group, setting it's representative to the representative of the larger group.
@mostafaelmenbawy5473
@mostafaelmenbawy5473 2 года назад
So you use Union Rank (aka Weighted Quick Union) together with Path compression. Which ends up with T O(1) find and union?
@ritesh_sinha
@ritesh_sinha 3 года назад
Great video series
@FrazerKirkman
@FrazerKirkman 11 месяцев назад
at 3:27, wouldn't it have been better if everything pointed to G?
@kutilkol
@kutilkol 5 лет назад
4:51 I think "compressing" J to H is not justified in vid. you are not doing Union(J,H) nor Find(J) :(
@sunnilabeouf
@sunnilabeouf 3 года назад
J and G have the same root, which is H. The union function calls find(j) and find(g)
@subee128
@subee128 4 месяца назад
Thanks
@lilybohr
@lilybohr Год назад
Thank you!
@blasttrash
@blasttrash 3 года назад
What if I want to increase the size of my array? Initially the array is initialized as 100 say, and I now want to add new element, how does this algorithm tackle that?
@rainymondays7541
@rainymondays7541 7 лет назад
Why don't we compress the whole tree after union rather than just the nodes we would like to merge while searching for their roots ?
@WilliamFiset-videos
@WilliamFiset-videos 7 лет назад
The answer is we're compressing the whole tree is a lazy fashion. Why bother compressing nodes we're not going to use?
@myeverymusic
@myeverymusic 5 лет назад
@@WilliamFiset-videos lazy compress :)
@luongtran5055
@luongtran5055 6 лет назад
you are genius, one of the best explanation!!!
@user-lu6vt7ib5x
@user-lu6vt7ib5x 3 года назад
thank you!!
@sudonick-kn5zn
@sudonick-kn5zn 8 месяцев назад
hello prime's chat!
@tariqkhasawneh4536
@tariqkhasawneh4536 5 лет назад
Does path compression implies using trees as a data structure for the union find, and without compression means relying on linked lists?
@stefanrendevski1837
@stefanrendevski1837 5 лет назад
A bit late, but no. Path compression does not impose an underlying implementation data structure. You can achieve path compression using an array by modifying the stored values
@securityintech
@securityintech 4 года назад
I have one doubt, if we do path compression, we would lose our previous root nodes, so we cannot revert them back :(
@JanacMeena
@JanacMeena 3 года назад
We don't need to revert back, since we never un-union
@tirthjayswal9895
@tirthjayswal9895 4 года назад
Good
@JanacMeena
@JanacMeena 3 года назад
5:10 Something that confuses me is that we are compressing the path during union command, but in your source code we compress during find() method
@domicasantoso96
@domicasantoso96 3 года назад
www.geeksforgeeks.org/union-find-algorithm-set-2-union-by-rank/ I think the general case is that whenever we execute a union call, we run a find on the two arguments as well.
@z08840
@z08840 3 года назад
it's not clear at this stage what's the point of all of this - since all nodes are connected you can simply point all nodes to one - no need for "instructions". If the point was to show disjoint components then this example is awful - there is no disjoint components.
@akhilvaid6889
@akhilvaid6889 4 года назад
omg stop using purple, im color blind, cant distinguish subtle difference between blue and purple. Green would be good!!
@emilyding4676
@emilyding4676 3 года назад
it's a kind of bad animation. If the animation made more clear, then it is easier for beginners to understand more.
Далее
Union Find Code
7:41
Просмотров 74 тыс.
Будзек и рецепт🐝
00:25
Просмотров 109 тыс.
Lenia - Artificial Life from Algorithms
13:15
Просмотров 133 тыс.
Fractals are typically not self-similar
21:36
Просмотров 3,9 млн
Priority Queue Introduction
13:18
Просмотров 452 тыс.
Disjoint set UNION by RANK and Path Compression
26:48
How Dijkstra's Algorithm Works
8:31
Просмотров 1,3 млн
What happens at the Boundary of Computation?
14:59
Просмотров 63 тыс.
Union Find - Union and Find Operations
10:53
Просмотров 248 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08