Union Find Path Compression

preview_player
Показать описание
Related Videos:

Data Structures Source Code:

Рекомендации по теме
Комментарии
Автор

Holy mother of clarity. Great explanation, bro.

ErnestoEnriquez-dujj
Автор

Thank you for explaining these concepts so beautifully. Please keep posting new videos. Thank you so much.

vishalmishra
Автор

Thank you so much it is extremely helpful. One image's worth 1000 of words

Sulerhy
Автор

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?

khadijahflowers
Автор

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.

loloioi
Автор

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.

kevinpreston
Автор

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.

therealbnut
Автор

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 :(

pedrobraga
Автор

At 4:09, after Union(H, F), why H points to E? H's group is larger.

garceaalex
Автор

Savior. Thanks for this amazing content ! :)

ayushijmusic
Автор

At 4:10.
After executing Union(A, C) the 3rd instruction in right column, why did B point to C. I expected B to D instead because shouldn't it always be root of group1 to root of group2?;

5:25 "hadn't even finish all the instructions and we have reached the final state"
What instructions? What final state? How can final state be reached without finishing an algorithm? Do you mean there are some useless instructions at the end of path compression that can be ignored due to some condition?

Why is C and A pointing to E through D, instead of to E directly? I thought compression means all nodes to final parent in single step.

Han-veuh
Автор

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?

shijieru
Автор

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!

thiagomelo
Автор

brilliant and easily explained thhanks

adityasahu
Автор

At 3:24, should we also point A B C D E to G instead of F?

RohithMusic
Автор

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?

Yan-rvmi
Автор

So you use Union Rank (aka Weighted Quick Union) together with Path compression. Which ends up with T O(1) find and union?

mostafaelmenbawy
Автор

3:22 Would you not make E, D, C, B, A parents all G?

hamza-chaudhry
Автор

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.

swordwaker
Автор

at 3:27, wouldn't it have been better if everything pointed to G?

FrazerKirkman