Design disjoint sets which supports makeSet, union and findSet operations. Uses union by rank and path compression for optimization. github.com/mission-peace/inte... github.com/mission-peace/inte... / tusharroy25
Пікірлер: 314
@gregross56515 жыл бұрын
All students are saved by Indian Tutors on KZfaq. Thanks India !!
@adhishmalviya24083 жыл бұрын
🇮🇳 I love my India!
@043_fazlerabbi52 жыл бұрын
Allah saves us all.....
@tryler4494 жыл бұрын
I swear, every time I see Tushar walk in front of the camera I can't help but smile. Thanks for being such a friendly and righteous dude.
@prashishh9 жыл бұрын
Absolutely love your videos. I'm currently preparing for my interviews and your videos have been the go-to for me so far! Keep up the great work and thanks a million.
@Nihilish6 жыл бұрын
This video is amazing. It's explained so clearly, and it was a great idea to showcase the theory first, and then demonstrate the implementation. Great work man!
@akankshasharma7498 Жыл бұрын
0:05 What is Disjoint Set? Disjoint Set is data structure that supports the following operations: a. make set: create a set with only 1 element in it b. union: take 2 different sets and merge them in one c. find set: to return the identity of a set Identity of a set is usually an element of the set that acts as a representative for it Use Cases: 1. Kruskal's Algorithm 2. finding cycle in an undirected graph 0:38 Implementations: 1. using rank and path - uses a tree - node: int rank int data node parent a. make set: 1. initialize n nodes with data and rank=0 2. make parent of all nodes point to the node itself b. find set(node): 1. dfs to a node that points to itself (root) 2. path compression: node.parent=root 3. return root c. union(a, b): 1. A=find set(a), B=find set(b) 2. if A==B => already in the same set 3. if(A.rank>B.rank) make A te parent of B and increments its rank by 1 vice-verse 11:07 Time and Space Complexity for m operations and n elements Space: O(n) Time: O(m.α(n)) ≈ O(4m) ≈ O(m) 11:57 Code
@reshmaarul8637 Жыл бұрын
if A.rank > B.rank you shouldn't increment the rank. when both the sets are of same depth/rank only you have to increment the rank. if (A.rank > B.rank) B.parent = A; else if (B.rank > A.rank) A.parent = B; else { // both are equal so pick any B.parent = A; // A is the parent now A.rank++; }
@akankshasharma7498 Жыл бұрын
@@reshmaarul8637 thanks man, lemme edit that
@Jonatube28 жыл бұрын
Brilliant, really helps to watch your videos before reading about the topic at hand! Ty very much, keep up the good work :)
@saravanaprabhukarunakaran36678 жыл бұрын
You can have a special talent of making anything complex look very simple. Thanks Tushar
@minrengwu21344 жыл бұрын
Wonderful!! The simplest explanation I have ever seen on disjoint set and union-find!!
@conintava5147 ай бұрын
Perhaps the most helpful disjointed sets video I've come across so far, thank you!
@davidvader72108 жыл бұрын
Wonderful video, very clear and very concise. My class didnt bring up "rank" but it really helped me understand. The use of code at the end was AWESOME
@shubhampathak10806 жыл бұрын
Great video ! This video was handy while brushing up the basics of algos. Keep up the good work, really appreciate it.
@wenyuewang58426 жыл бұрын
people like you make this world a better place!
@muskanroxx223 жыл бұрын
only if you walked through the code of every problem like you did in this one!! Great work Tushar! You're still helping people after 6 years!!
@brianlau27578 жыл бұрын
Thanks! This is helping me get through my cs class in college
@sapotico8 жыл бұрын
Just a small little note: when he's saying 2 goes to zero (10:20), it should have been 1. He was reading the new rank of one which was zero (I just don't want anyone to be confused). Excellent video and explanation! Thanks a lot!
@RAJAT2811936 жыл бұрын
2 goes to real parent only when will perform find operation ,then all the member in the path will goes to main parent directly . this is will not the case for union. check code once
@ahmedghazy57964 жыл бұрын
Awesome!! nice one covering all I need to know about disjoint sets to be able to apply it into problem solving
@Joyddep4 жыл бұрын
One of the best executed implementation with superb explanation. Thanks a lot.
@anurag98508 жыл бұрын
The video made my day... Was stuck in disjoint sets for 1 day. Keep it up :-)
@amitgp20078 жыл бұрын
you are THE BEST Sir.. These are best videos on algorithms and data structures.
@KaylaRen6 жыл бұрын
Your video is always the best, helped me a lot of algorithms that I tried hard to understand.
@AnkitVerma-yn3ku5 жыл бұрын
This is the finest videos on disjoint set available on KZfaq Thanks Tushar for great explanation just a minor error 9 instead of 1 rank will be 2
@sakshamsharma57976 жыл бұрын
Impressed by your teaching skills :) Thank you for the awesome videos.
@bioinfo93868 жыл бұрын
.. great help for me as well!! Even more descriptive than the chapter in Cormen´s Algorithms..thanks a lot for your support!!
@ankitsingh-rb8pc4 жыл бұрын
This is the best explanation available on internet
@atuljain28455 жыл бұрын
You really made this one simple to get. Thank you.
@debverine8 жыл бұрын
Excellent Tushar, this solved my doubt :) . Was stuck for last 2 days !!
@sumankashyap18 жыл бұрын
Great work !! Very nice and simple to understand explanations !
@anirbanmaity936 жыл бұрын
Just awesome. I did not get this much of understanding from ny book. thanks a lot.
@VojtechMach6 жыл бұрын
helped me out big time once again. thank you!
@987654jef9 жыл бұрын
Ótima explicação! Great work again.
@priyanshagarwal20952 жыл бұрын
after 5 year also your videos are great,,, i was not able to understand clearly in any video then i came here, , FINALYY DONE
@mgorasia8 жыл бұрын
Dude you are awesome. Continue the good work!
@pisithyim91987 жыл бұрын
Best disjoint sets video, thank you for sharing.
@cavalcanteluiz4134 жыл бұрын
Thank you for the explanation, it helped me a lot!
@azzaea8 жыл бұрын
Very elaborate explanation! Thank you!
@glaucoa.92143 жыл бұрын
Tushar thanks, I finally learned all about ranking union. Very happy for your video congratulations, I will follow your channel now.
@nalnalnalnal488 жыл бұрын
Thank you, now that i can understand even kruskal's algorithm in a flash. Great video ;d
@lavanyam32243 ай бұрын
I already watched videos on union by rank and didn't quite understand why we're incrementing rank for a few cases and why not for other cases. Your explanation made it so clear! We'll increment rank only if both the sets are of the same rank, otherwise, we just make a union 🙂
@bitlegend007 жыл бұрын
I know you already receive a lot of praise, but god damn you are good at this. Thank you.
@dustin_echoes8 жыл бұрын
My professor wouldn't explain shit in the lectures. Great video! It really helped!
@kiranbandagar25726 жыл бұрын
excellent video..cleared all doubts in very less time...thanks a ton sir...
@jineshdhruv61516 жыл бұрын
Thank you for the great explanation and clean code!!!!!
@partheshsoni64213 жыл бұрын
Love your videos man!
@vikrammondal58115 жыл бұрын
Thanks a lot for this video. BEST VIDEO FOR THIS TOPIC
@eliyahubasa94016 ай бұрын
Your videos are the best!
@shanugupta2966 жыл бұрын
precise and good explanation. Keep it up the good work :)
@anujrai6057 жыл бұрын
nice video.........has definately helped me in understanding the concept of disjoint set
@pritishthakkar71238 жыл бұрын
Very nice and well explained video !! gr8 job sir !!!
@priyanka.sarkar5 жыл бұрын
When the path compression happens in findSet, there should be a change in rank in this case as well. Rank of root with data = 1 shouldl be 2. Although there will be no problem in this particular example but if instead of union(7, 13), it was union(7, 14) then due to path compression the rank of both the trees would change(the root with data 1 should be 2 and the root with data 11 should be 1) and after setting the parent of 11 as 1, the final rank of root 1 should be 2. But in this code, the rank is not getting updated which might lead to a problem in further unions which may involve a node in this component.
@juggles54749 ай бұрын
Non-root ranks don't matter which Tushar mentions, since we'll only be merging using the rank of the parents
@saikalyan19163 жыл бұрын
Thank you dude what great explanation. Excellent video !!!
@DarkGreiga8 жыл бұрын
very good, very helpful, and understandable for me even though english isn't my first language. thanks for sharing!
@tanurampal13585 жыл бұрын
Amazing video! And the first person Ive heard use whom correctly in one go.. haha
@swetabjahazra80508 жыл бұрын
Best Data Structures and Algorithms videos on youtube!!!!!!!!!!
@blasttrash5 жыл бұрын
Not anymore. Abdul Bari is here to transform everything. Check his channel. He doesnt stammer and talks slowly and his videos are crisp. No offense to Tushar though
@AbhishekKumar-im2xd4 жыл бұрын
Abdul bari is a beauty... He is a gem💎💎💎😍😍😍
@RakeshSingh-hb7rj4 жыл бұрын
@@AbhishekKumar-im2xd yes!!
@rohitk4725 ай бұрын
@@blasttrash Tushar Roys explanation is top notch...
@blasttrash5 ай бұрын
@@rohitk472not really, he jumps directly into say choosing dynamic programming or assuming that its greedy without explaining the reasoning behind it. There are many newer youtubers who explain things better.
@divyanganachaudhary31649 жыл бұрын
Awesome explanation sir ! Gud work !
@anyu81098 жыл бұрын
unbelievable clear and easy to understand.
@sword0133 жыл бұрын
7:42 Rank of 6 will be (1) itself, only 4's rank increased to 2, but then as sir said, it won't matter what is the rank at the non-root node, we're never going to see them, so doesn't matter if its 1 or 0 or any other number. We're concerned only about 4's rank.
@jitender17128 жыл бұрын
nice video to learn how to represent disjoint sets and operations performed on it
@chadmalla7 жыл бұрын
Can you please make a video explaining amortized analysis?
@alessiodenny61234 жыл бұрын
excellent ! This video saved me from failing my midterm
@learnhumanity67012 жыл бұрын
And thank you so much for this video it helped me in the middle of the night to understand this concept ❤
@puffvayne56882 жыл бұрын
That findSet function with the path compression is so fucking clever, nice dude!
@ewoutmerckx57498 жыл бұрын
Great introduction! :D
@chengzhiyang81765 жыл бұрын
Thank you! you made it simple!
@zjyj520520dd8 жыл бұрын
Thank you for your video, now it makes so much more sense to me! I have a question what if the findset number is the root, does the map just not change at all?
@abhinavaman80083 жыл бұрын
yes, cause when we will get the node and the parent and compare them then if the condition will give true cause they are equal and then we will simply return. Though I know you must not need this reply after 5 years but replying just to make you nostalgic
@sotiristotomis3327 жыл бұрын
Hello and thank you for this tutorial. But there is something I want to mention. All the parent pointers of the roots must be null, this will help to find the root of each node using a while loop in O(h).
@RalyJoey7 жыл бұрын
I'm confused with the RANK. It seems that rank is determined by the higher ranked set when performing the union rank, i.e., union(set_m rank1, set_n rank0) results to be rank1. Does that indicate rank won't change as we keep attaching rank0 set to another set?
@achuachu62963 жыл бұрын
me too
@amandixit35553 жыл бұрын
@@achuachu6296 Rank will change iff we try to union two elements of different sets having same rank . else the higher raked set will always be the parent of lower ranked set.
@user-kg2ql5sh8u2 жыл бұрын
Thank you so much, Ray William Johnson!
@1gouravgg7 жыл бұрын
beautifully written code.. so simple.
@faisalalmamun43125 жыл бұрын
Thank You for awesome explaination
@rayanajjar61428 жыл бұрын
thank you very much,you are explaining the material very good
@mohammadkaifkaif54418 жыл бұрын
tushar bro,really great video :)
@waytoanand3 жыл бұрын
Tushar videos are fast and great but in this video another thing to notice is : 12.05 Tushar talks in native language and now we know he is desi guy :)
@rutvikrana5123 жыл бұрын
So much good explanation 🤗
@sujayshanbhag2055 Жыл бұрын
This video is criminally underrated
@heesukson35813 жыл бұрын
The best explanation!
@yangsong48392 жыл бұрын
Your code is so clean!
@DeepakSharma-di2fd9 жыл бұрын
simply awesome bro..
@ahmedal-ahmed76067 жыл бұрын
Great Tutorial !! Thanks
@guvenim7 жыл бұрын
good tutorial, keep the good work
@rohitbajaj77332 жыл бұрын
best explanation, made it simple!
@mrm2596 жыл бұрын
Hi, thanks for your video. I'm wondering rank node 1 at 10:10 second should be 1 why you change it to 0 ?
@abhishekp033 жыл бұрын
Thank you, Tushar :)
@nikhilgohil88083 жыл бұрын
Simply amazing!
@oussamamoussaoui71312 жыл бұрын
great explanation, thanks
@overdrivegain4 жыл бұрын
Hello Tushar, my name is Manar and I wanna thank you!
@SantoshKumar-bu2qr5 жыл бұрын
10:56 isn't the rank of node 4 becomes 1 (depth of the tree after path compression) ?
@pradiptalekar91358 жыл бұрын
Excellent videos dude
@ilyanaoumov54257 жыл бұрын
When you run through the path compression logic, shouldn't the rank decrease for each disjoint set when there is an optimization to be had? For example, when you first merge 2 sets, you might have a rank of 3. After you use findSet(), doesn't the rank fall back down to 1?
@sandepkv833 жыл бұрын
U save a lot of time... Tqs man.
@ashugupta86096 жыл бұрын
thanx it was really helpful, pls can you explain about the other implementation like kruskals and diskestra too.
@SaurabhPatel8 жыл бұрын
Such a Great video
@SaurabhPatel8 жыл бұрын
+Tushar Roy at 9:51 Why you should increment the rank by 1. Both are not equal, One rank is 2 and Second rank is 1, So thats totally fine as per algorithm. If both rank are same then and then we need to increment any one of them by 1. //increment rank only if both sets have same rank parent1.rank = (parent1.rank == parent2.rank) ? parent1.rank + 1 : parent1.rank; parent2.parent = parent1;
@SaurabhPatel8 жыл бұрын
+Tushar Roy thanks.
@RAVIKUMAR-ef4wo5 жыл бұрын
Thanks a lot Tushar
@Manu-wb2uv2 жыл бұрын
Interesting data structure :)
@benjenkincpa8 жыл бұрын
Excellent video.
@aruldhanasaamprakash5 жыл бұрын
Damn good explanation. :-)
@1994ranjeet7 жыл бұрын
very useful video ..helped a lot
@pradeexsu4 жыл бұрын
Thsnks sir for amazing tutorial
@ramum54247 жыл бұрын
superb explanation
@ronaqbehura88742 жыл бұрын
When using path compression along with union by rank, the rank might be incorrect on application of the path compression algorithm. I have found union by size and path compression to be logically correct where path compression doesn't affect union by size at all. Any thoughts on this ? Would appreciate if anybody can point out if I'm missing out on anything for Union by Rank + Path compression