Comment down any questions below! Please give it a like and subscribe to support our channel. Cheers, Potato Coders 🙂
@cartooncartel64934 ай бұрын
Bro you cooked
@robirahman2 жыл бұрын
You forgot to mention you have to union the shorter tree into the longer tree! Otherwise the trees in a set of n elements can be up to n elements long (just a straight chain, instead of branching) and you don't get log(n) complexity.
@tunguyenxuan82962 жыл бұрын
true. if we represent the group as a tree, it will take O(n) for find function in worst case. We better to represent a group as a trie, where all children point to one root.
@neerajvshah Жыл бұрын
@@tunguyenxuan8296 Trie's don't change the runtime complexity, a trie is just a type of tree (keep in mind not all trees are binary trees, a trie is just an k-ary tree). As Robi mentioned it's path compression which makes union find efficient. This video is incorrect - O(logn) is never the time complexity for union find. It's either O(n) without path compression or O(a(n)) with path compression.
@lightlysal Жыл бұрын
@@neerajvshahWhat's a(n) mean in your explanation? Is it the amount of times we "compress" a parent? I thought when people say the time complexity of union find they mean O(log N) on average over all use cases
@sirmonke8946 Жыл бұрын
@@lightlysal a(n) is the reverse ackermann function. It grows insanely slow (slower than any log) and can basically be rounded to constant time
@MrKlaygomes Жыл бұрын
@@neerajvshahpartially correct, if it is only weighted without path compression it is O(log n).
@BobTheScience11 ай бұрын
To optimize it, the find function should set the parent of it's parent to find(x). (This will probably help a lot) function find(x): if Parent[x] != x: parent[x] = find(parent[x]) return parent[x] If I'm wrong please tell me.
@nomealow4 ай бұрын
Yes, this is called path compression, by setting the parent of x and all of the ancestors of x to be the root ancestor of x. This makes it so that find(), for that particular tree in the future, will be O(1) instead of being dependent on the tree depth
@luisgualpa70193 жыл бұрын
This video has saved me many hours of my life. Thank you for this.
@potatocoders20283 жыл бұрын
I'm so glad!
@richtigmann1 Жыл бұрын
This was actually insanely helpful in understanding the concept. Thanks!
@tenminuteamateurhour Жыл бұрын
Correction, this does not run in O(logn), but in O(n). To get O(logn) optimization, you need to use union by rank or by size.
@Coffeycup273 жыл бұрын
Awesome video, thank you! Question though; isn't the find operation O(n) time? I'm reading around that it isn't until you use 'Union By Rank' that it becomes O(log(n)).
@jakubucinski2 жыл бұрын
There is a little technicality, that when you do find(x), you want to do path compression, by connecting each vertex on the corresponding branch (the branch where x is) to the root. This results in subsequent find operations being cheaper (and you only double your cost one time).
@rm-stl2 жыл бұрын
I’ve seen this done but never heard it explained. It looked odd to have a side effect in a find(). Makes perfect sense now. Thanks
@stevenhicks3321 Жыл бұрын
I also noticed this and thought it may be better to use sets if you don't care about the three structure of the disjoineted set.
@pieterjanvandecasteele1353 жыл бұрын
I was always stuck with the implementation of UF, now I finally got it, thanks!
@potatocoders20283 жыл бұрын
You're welcome!
@vishaldhawan92363 жыл бұрын
+1
@danielwang88336 ай бұрын
Really clear and concise explanation. This video helped a ton.
@nightmare_93 жыл бұрын
Crystal clear and precise...Thanks!!
@potatocoders20283 жыл бұрын
Glad it was helpful! Also I like your profile picture :)
@estebanzavala953312 күн бұрын
wow really good preparing for an upcoming interview
@jerrygord313113 күн бұрын
This was really helpful, thank you!
@nghiapham1632 Жыл бұрын
It so simple and straight forward. Thanks you so much
@Anirozannay3 жыл бұрын
You explained it so well! Thank you for your video!
@potatocoders20283 жыл бұрын
Thank you! We hope it has helped!
@tudorradu58483 жыл бұрын
@@potatocoders2028 it helped me a lot, thank you man!
@송예은-h7b3 жыл бұрын
So practical and helpful video=) Thanks
@kmishy3 жыл бұрын
Best illustration... please provide more content
@Shasol3 жыл бұрын
How do you select the representative? I struggle to understand that part of it.
@UsamaAziz-lb7ky4 ай бұрын
Great video, worth adding path compression as well.
@jashmerchant512110 ай бұрын
Solved my hours long quandary in 5 minutes. Thank you!
@shamitfatin35163 жыл бұрын
under-rated video.. thanks for the explanation
@vinitsunita3 ай бұрын
Awesome explaination
@chrisdahms9682 Жыл бұрын
Bro this topic is confusing AF, but at least this vid makes it somewhat understandable
@manojmpatil1269 Жыл бұрын
Perfectly explained. Thanks
@donaldcodes2 жыл бұрын
Love it man, short and clear!
@alesblaze47452 жыл бұрын
wow , i must say that this was really easy and nice video , really nice explanation
@gregoriuswillson4153Ай бұрын
Great content bro
@samruddhisaoji71952 жыл бұрын
Loved this bite sized explanation!
@JamesBrodski2 жыл бұрын
Thank you so much this is great!
@chrismiaomiao9426 Жыл бұрын
Amazing! It's very clear. Thank you
@bozecki3 жыл бұрын
Thanks bro, now I finally understand it for tommorow exam ;p
@civilspot591210 ай бұрын
Great explanation
@ahmetemin7572 Жыл бұрын
Short and clear, thanks
@SterlingVanlaere3 жыл бұрын
Excellent video, thanks!
@potatocoders20283 жыл бұрын
Glad it helped!
@piotr7802 жыл бұрын
best explanation every ! :D
@Baal30333 жыл бұрын
Awesome explanation, thank you!
@potatocoders20283 жыл бұрын
Np :) I am glad it helped
@Hdhdushzhz577439 ай бұрын
Thank you! This was very helpful
@aadityakiran_s Жыл бұрын
You got a video on path compression?
@Dev_God2 жыл бұрын
Thanks for sharing! It's very clearly and efficiently explained!
@OtitoAmuga29 күн бұрын
This not efficient. "Set the root of one tree to the child of another" Another what? Another node? Another number? Another graph? Lol 😅
@OtitoAmuga29 күн бұрын
Mediocre at best
@Dev_God28 күн бұрын
@@OtitoAmuga Thanks! I'll get to know more about this.
@jeresher68213 жыл бұрын
Best video I've found on UF. Thank you!
@potatocoders20283 жыл бұрын
Wow, thank you for the great comment! :)
@persas1683 Жыл бұрын
Thank you very much. Nice video.
@mykz8147 ай бұрын
bro... come back ur vids r so good 😭
@waynegreen79704 жыл бұрын
Good content!
@potatocoders20284 жыл бұрын
Thank you. Let me know if there is any more content that you would like to see! 😀
Thanks and other implementations include rank. Does it matter?
@arjunv7055 Жыл бұрын
wonderful explanation! Thanks mate!
@jubiliudu3 жыл бұрын
Amazing! thank you!
@adam23sp2 жыл бұрын
Amazing video, very easy to follow, thank you! 🎉
@collyyang96643 ай бұрын
good, thank you very much
@paccini12 жыл бұрын
Wow, thanks a lot, great explanation!
@samwilson45972 жыл бұрын
Thank you so much man
@DeepakSankar88 Жыл бұрын
Great explanation. Was able to recall what I had learnt a while back. Thank you!
@chku Жыл бұрын
This video is so gud but looks like the channel ain't active anymkre 🥺💔 I really loved the explanation n quality so thankuu n hope u r doing well ✨
@WebSurfingIsMyPastime Жыл бұрын
This video was great! definitely not something that's very clearly covered in alot of other sources
@Rockyzach88 Жыл бұрын
Thanks Mr. Tater.
@pamp3657 Жыл бұрын
good video
@MinhPham-eh6lr2 жыл бұрын
Thanks for the concise and easy-to-understand explanation!
@tudorradu58483 жыл бұрын
THANK YOU!
@rasheedlewis1 Жыл бұрын
The Big-Theta runtime for find() would be Θ(n).
@mehraan85924 күн бұрын
beautiful
@algorithmdatastructures92444 жыл бұрын
Subbed 💛
@potatocoders20284 жыл бұрын
Thank you ☺️
@corgirun78922 жыл бұрын
awesome
@Luca_0408 ай бұрын
Wer sieht das auch für's HAW Studium?
@kmishy3 жыл бұрын
algorithm was easy but you should write code and execute
@helloyogeshpatel2 жыл бұрын
That’s how Algo is studied
@errorless7921 Жыл бұрын
Yes important is implementation
@mahlahlana3 жыл бұрын
wow!
@KoScosss2 жыл бұрын
Thanks
@emerald_eyes3 күн бұрын
Didn't know I'd be learning computer science from Jaqen H'ghar
@JackSparrow-vv2uq3 жыл бұрын
Thank you
@samuraipiyush Жыл бұрын
beauty
@moshebixenshpaner50942 жыл бұрын
There are two issues here: 1. When performing union, you set parent of the smaller set to the representative of the larger set. 2. When finding a path, you compress the path on your way back, improving O(logn) ops to O(log* n) in average.
@CSSFACE2 жыл бұрын
what do you mean by O(log* n) what is the *?
@supratimdas10063 ай бұрын
@@CSSFACE study
@OtitoAmuga29 күн бұрын
Bro speaking not exactly matching what he's saying. I guess that's why he's a potato coder.