Union Find - Union and Find Operations

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 78

  • @terrordoger7837
    @terrordoger7837 3 роки тому +19

    I found myself losing track of his train of thoughts or mid sentence sometimes, playing this at 1.5 speed really helped me understand it better!

  • @gabrielahernandez4236
    @gabrielahernandez4236 4 роки тому +68

    this is literally saving my life and WAY easier to understand than the class I'm taking lol. thank you!!

    • @adhishmalviya2408
      @adhishmalviya2408 4 роки тому

      Do you have education loan to repay?

    • @turuus5215
      @turuus5215 2 роки тому +1

      Seriously, youtube educators save our lives.

  • @lfhao7969
    @lfhao7969 5 років тому +143

    good video, 1.25 speed makes it perfect.

    • @uzeyirveli
      @uzeyirveli 4 роки тому +18

      More like 2.0 :D

    • @user-rf4vc7mt4d
      @user-rf4vc7mt4d 4 роки тому

      @@uzeyirveli yess

    • @tombrady7390
      @tombrady7390 3 роки тому

      @@user-rf4vc7mt4d man you are dope please keep commenting on videos

    • @victoriaye3441
      @victoriaye3441 3 роки тому +1

      love your username lol@@user-rf4vc7mt4d

  • @ahmad-ali14
    @ahmad-ali14 Рік тому

    Classes are hell; this is much easier, thank you.

  • @krood_
    @krood_ 2 роки тому +2

    It pains me to see good videos like this are hidden in the algorithm while shitty videos with no efforts have so many views. Keep up the good work william.

  • @kartikxramesh
    @kartikxramesh 4 роки тому +7

    Path compression is what makes Union Find an absolute *BEAST* of a Data Structure xD

  • @ale-hl8pg
    @ale-hl8pg Рік тому +2

    Thanks man, just by listening to you and listening to you and seeing the illustration it kind of nailed the point to me, that union-find is pretty much just a generalization of grouping. Not necessarily "grouping" as some specific algorithm, but any problem that you come across which can be solved by grouping elements together like Kruskal's MST

  • @scriptkiddie6151
    @scriptkiddie6151 3 роки тому +5

    Man you are so underrated, you create amazing videos with concise explaination.

  • @akshatbhutra7278
    @akshatbhutra7278 5 років тому

    Very nice concept of implementation of kruskal using union-find

  • @advandizdarevic4987
    @advandizdarevic4987 4 роки тому +25

    Maybe I'm missing something but at 3:44 we are grouping the elements and shouldn't there be a pattern to who becomes who's parent ex. the lower ID becomes the parent or the first element that we pass to the function is the parent? Because first two examples are (C,K) = (4,9) = 4 is parent (lower id ), second example (F, E) = (0,1) = 0 is parent ( lower id ), and then in the third one (A, J) = (5, 6) = 6 is parent? I know this is not the point of the video but shouldn't it follow the same logic if there's any? Later on it makes sense that we are merging the smaller component into the bigger one to flatten the tree. Great video overall didn't mean to be a party pooper :P

    • @timgoppelsroeder121
      @timgoppelsroeder121 4 роки тому +2

      same problem for me the same logic shoould be used throughout in my opinion

    • @SaruulShafiq
      @SaruulShafiq 3 роки тому +5

      yeah, you are correct, william is not following any strict pattern here .. when doing it with code you would probably always take either the smaller or bigger id in those cases (merging two nodes pointing to themselves) .. but the good point of william not following a strict pattern here is that it shows that it does not matter which id you take so maybe it is even intentional :)

    • @wjrasmussen666
      @wjrasmussen666 3 роки тому +1

      @@timgoppelsroeder121 I agree with both of you.

  • @rhusselcombo7696
    @rhusselcombo7696 5 місяців тому

    🎯 Key points for quick navigation:
    00:01 *🔑 Explains the union and find operations in a union-find data structure.*
    00:17 *📝 Creates a bijective mapping between objects and integers to construct an array-based union-find.*
    01:05 *🗃️ Stores the mappings in a hash table for efficient lookup.*
    01:34 *📐 Initially, each node in the array points to itself as a root node.*
    02:30 *🔗 To unify objects, the smaller component's root node is set as the parent of the larger component's root node.*
    04:34 *🧰 Explains the process of merging smaller components into larger ones during unification.*
    06:24 *🌳 If two objects belong to the same component, no unification is needed.*
    07:42 *🔍 To find the component an element belongs to, follow the parent nodes until reaching the root node.*
    08:41 *🚩 The number of components equals the number of remaining root nodes and never increases.*
    09:48 *⚡ Path compression, covered in the next video, improves the time complexity of union-find operations.*
    Made with HARPA AI

  • @duo2375
    @duo2375 6 місяців тому

    Very descriptive. Thank you!

  • @caboosept8662
    @caboosept8662 4 місяці тому

    Good video! Helped understand everything
    And I watched in 1.0x 😂 i dont know why people find it hard to understand

  • @emmanuelnsiah8036
    @emmanuelnsiah8036 28 днів тому

    7:34 shouldn't c node point to e and shouldn't the index of 0 go to index of 4?

  • @DillonHuff
    @DillonHuff 3 роки тому

    Thanks for making this video. It was very helpful!

  • @terrordoger7837
    @terrordoger7837 3 роки тому

    At 5:44 he said that because the orange component has more elements than the green component, how would the program know that when we're just performing Union(C,A), we would have to iterate through both subsets?

  • @bharathateja2797
    @bharathateja2797 6 років тому +1

    all your videos are really helpful. thank you so much.

  • @Dan-tg3gs
    @Dan-tg3gs 3 роки тому

    im confused where those instructions came from. I think you made those up right? What would be an applicable problem to replace these instructions?

  • @huseyinbarin1653
    @huseyinbarin1653 2 роки тому

    I love your videos a lot. Thanks

  • @JinggaBlitz
    @JinggaBlitz 3 роки тому

    Thank for the nice video and concise understandable explanation.
    I am still wondering why we merge it as child of the root, instead child of the node as per the unify instructions

    • @ChrisCox-wv7oo
      @ChrisCox-wv7oo 2 роки тому

      you want to unify to the root to create the smallest depth of steps from root to leaf. same concept as when you unify two different sized groups, you unify the smaller group to the larger.
      path compression is a technique, that William isn't using here, that will actually reduce the depth of all groups to 2. the root and the child.

  • @greaterthanKTWS
    @greaterthanKTWS 6 років тому +1

    Hey, you went to my University! Awesome work!

  • @irvinge4641
    @irvinge4641 6 років тому

    we also have to keep track of how big the subtrees are right? the array structure we have is only keeping track of vertices? unless otherwise for every iteration we count how many elements have that same root node value which would be O(n)? But we can make it O(1)?

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 5 місяців тому

    great explanation
    thank you so much🥰🥰

  • @davidebussi3182
    @davidebussi3182 4 місяці тому

    i dont understand why you switched the definition of parent-son mid execution in the example with the letters

  • @ikaros9727
    @ikaros9727 4 роки тому

    Hey. What would happen in 5:22 if we had to union Node A with Node K? Would we attach J to C or J to K? As far as i understood we check which Union has more elements, and then attach the root node of the Union with less Elements to the Node we want to union it with.

  • @vasudevgawde4767
    @vasudevgawde4767 4 роки тому +1

    Your description has self-loop to the same video.

    • @knobtwista
      @knobtwista 4 роки тому +1

      Shoulda used union find lol

  • @MykhailoKovalykUA
    @MykhailoKovalykUA 7 місяців тому

    Not quite sure why K is child of C, but F is child E. According to first approach - E should be a child of F

  • @zuowang5481
    @zuowang5481 4 роки тому

    does every node track the size of its tail?

  • @JanacMeena
    @JanacMeena 3 роки тому

    To people like me, who didn't read the description- watch his first video first: ua-cam.com/video/0jNmHPfA_yE/v-deo.html

  • @only4music725
    @only4music725 4 роки тому

    In the case of two components having same amount of elements and being asked to merge which way is the arrow going to point ? Thanks,

    • @khailai5204
      @khailai5204 4 роки тому

      you can arbitrarily choose either one and merge it in as the child of the other tree/component.

  • @АйбатАманбайұлы
    @АйбатАманбайұлы 4 роки тому

    Good day!
    In the remarks session, @10:15 => it says that in the current implementation, there is 5 hops to find out whether roots of two components are same or not.
    However, in the array-based implementation, every value of indexes point right to the root node. So, isnt it always 1 hop for each?
    Maybe I'm missing something. Sry for this

    • @krzysztof9287
      @krzysztof9287 4 роки тому

      > every value of indexes point right to the root node
      example from the video does not use path compression (and you can verify that there are 5 hoops by looking on array - 7:40)

  • @lidiatjr
    @lidiatjr 2 роки тому

    Great video, thank you so much!

  • @irvinge4641
    @irvinge4641 6 років тому

    would it be also valid if I use hashmaps and hashsets instead?
    map: {
    a: {}
    b: {}
    ....
    }
    merge(a, b) {
    combined = new Set(map.[a], map.[b])
    map[a] = combined
    map[b] = combined
    }
    find(a) {
    return map[a]
    }

  • @sebastianrollino741
    @sebastianrollino741 3 роки тому

    This is just a weighted union find right?

  • @marilynmosala8018
    @marilynmosala8018 7 років тому

    Awesome channel! So easy to understand!

  • @ouroboros7388
    @ouroboros7388 2 роки тому

    This question might be really dumb but how do I do the mapping (object to number)? Thanks for the help and for the awesome video!

  • @shahriarmim4696
    @shahriarmim4696 5 років тому

    from 5:27 could we merge the orange component to the green component?
    to be more precise, Node C points to J. Here J become parent of C
    can we do that ? If not, please tell why ?

    • @shahriarmim4696
      @shahriarmim4696 5 років тому

      @Patrick Watts number of hops ? I don't get it :/

  • @pedrobraga4944
    @pedrobraga4944 Рік тому

    Great video, but I didn't understand the remarks :/
    More precisely the statements:
    "we would have to update all the children of a node" and "the number of components is equal to the number of roots remaining"

  • @spaceburgers
    @spaceburgers 7 років тому

    these videos are really phenomenal I appreciate it!

  • @blazzy95
    @blazzy95 7 років тому

    what if there are three nodes in group orange and in group green and we try union operation of union (orange, green) .... do we arbitrarily choose the group for the root node ?

    • @WilliamFiset-videos
      @WilliamFiset-videos  7 років тому +4

      blazzy95 The choice of the successor root node is arbitrary. Generally I merge the smaller group into the larger one but this does not affect functionality

  • @chavotv8752
    @chavotv8752 6 років тому +1

    in min 3.55, I think E should = 1

    • @myeverymusic
      @myeverymusic 5 років тому

      My first thought was that E should be 1 too. Then i watched video twice, he randomly defined parent in each union :)

  • @sanskarshrivastava5193
    @sanskarshrivastava5193 2 роки тому

    great videos man !

  • @undefinedrahulraj
    @undefinedrahulraj 3 роки тому

    Hey William... Thanks for making and sharing such nice videos on DS and Algorithm. Do you have slack channel or Discord Server where we can connect with you and discuss on these topics directly ?

  • @vijethkashyap151
    @vijethkashyap151 6 місяців тому

    Beautiful!

  • @chavotv8752
    @chavotv8752 6 років тому +2

    is it ok if you are not being consistent?

    • @josh100CH
      @josh100CH 4 роки тому

      ChavoTV yes, union is commutative. You should however map the smaller to the larger component due to the run time of the find operation.

  • @usagiliu2104
    @usagiliu2104 7 років тому

    Great video!! Thank you:)

  • @moezetaib4593
    @moezetaib4593 4 роки тому

    Thanks

  • @know1374
    @know1374 5 років тому +1

    I'm mystified now

  • @geekwithabs
    @geekwithabs 4 місяці тому

    I didn't quite understand the concept after I watched this 3 times, so watched ua-cam.com/video/ayW5B2W9hfo/v-deo.html and then came back to this video and totally loved the explanation. Thanks much for uploading.

  • @Lordvibrane
    @Lordvibrane 4 роки тому

    Epic Video :)

  • @EranM
    @EranM 6 місяців тому

    x1.5

  • @mizutofu
    @mizutofu 4 роки тому

    code samples would be more helpful than just diagrams

  • @trava4156
    @trava4156 4 роки тому +1

    bro, can you literally make it ANYMORE boring? I doubt it... -_-

    • @gabrielahernandez4236
      @gabrielahernandez4236 4 роки тому +5

      wow ruuude. it's literally an informational video and the material is really well explained. i don't think it's boring

    • @timgoppelsroeder121
      @timgoppelsroeder121 4 роки тому +3

      Well "bro" what are you doing here?.... this is supposed to help you with studying... first priority wasnt for you to giggle like a little girl behind your laptop screen....... Nonetheless i hope you find topic matter more accomodating to your needs (TIP: Keeping up with the kardashians, moonshiners etc. are prime sources of entertainment for your ilk)

  • @subee128
    @subee128 7 місяців тому

    Thanks