Disjoint Set Union By Rank and Path Compression | DSU | Graph Concepts & Qns -19| Explanation+Code

Поделиться
HTML-код
  • Опубликовано: 26 июл 2024
  • Hi Everyone, this is the 19th video of our Playlist "Graph Concepts & Qns".
    In video-18, we understood a very important topic in Graph "Disjoint Set Union (DSU)"
    In this video we will see the optimized version of DSU using Rank and Path Compression.
    Problem Name : Disjoint Set Union By Rank and Path Compression
    Topic : Graph
    Video : 19
    Company Tags : Google, Facebook, Apple, Amazon, Netflix, Flipkart
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    0:00 - Intro & Recap
    1:20 - Understanding Path Compression from Example
    8:12 - find() using Path Compression
    10:04 - Understanding Rank from Example
    12:55 - Why Larger Rank is chosen as Parent
    17:04 - union() using Rank
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
    #interviewpreparation #interview_ds_algo #hinglish

Комментарии • 75

  • @codestorywithMIK
    @codestorywithMIK  Год назад +34

    Guys, today’s Leetcode Challenge will be uploaded now. Stay tuned today ❤

    • @souravjoshi2293
      @souravjoshi2293 Год назад +2

      Thanks a lot man ❣.
      You have earned our request.

    • @compiled9787
      @compiled9787 Год назад +2

      Most awaited video

    • @oqant0424
      @oqant0424 Год назад +2

      itna wait to fifa ka bhi ni kiya tha🙄

    • @harsh-singh
      @harsh-singh Год назад +2

      ok brother , jaldi kar dena ❣.

    • @compiled9787
      @compiled9787 Год назад +1

      Kab upload karoge yaar?

  • @bandariAkshay-js1lv
    @bandariAkshay-js1lv День назад +1

    This explanation of Disjoint Set Union by Rank and Path Compression is amazing! ❤Thank you for breaking it down so well!❤

  • @AnshuHarshit
    @AnshuHarshit 14 дней назад +2

    Bhaiya DSU kya sach me itna easy hai..
    Thank you❣

  • @dakshmalik14
    @dakshmalik14 Месяц назад +6

    Jiska rank jyaada hai vo papa banega 😂😂😂 best line ... your teaching is top notch, thanks a lot❤

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 6 месяцев назад +3

    You are by far the best DSA tutor I have ever studied from 🙏🏻

  • @b_01_aditidonode43
    @b_01_aditidonode43 25 дней назад +1

    amazing explanation!!

  • @gauravbanerjee2898
    @gauravbanerjee2898 10 месяцев назад +5

    19/40 done ✅ thanks a lot bhaiya😊❣ you made disjoint sets, a cakewalk for us what a great explanation 🥹

  • @73-sarthakpandey25
    @73-sarthakpandey25 Год назад +4

    Your way of explanation is very good.This channel will see very much growth in the future.Hope you complete 100K this year

  • @Thriftinghai
    @Thriftinghai 11 месяцев назад +1

    You are doing wonders. I feel bad for those who are struggling to pay huge fees for paid courses and missing this legend's channel

  • @imsd17
    @imsd17 6 месяцев назад +3

    You are very Great at explanation also I like your approach to solving problems with stories.

  • @wearevacationuncoverers
    @wearevacationuncoverers Год назад +1

    This is one of the best explanations on DSU

  • @nawazthezaifre8870
    @nawazthezaifre8870 26 дней назад

    Amazing explanation !!!

  • @meetz_0166
    @meetz_0166 4 месяца назад +2

    bhai kya hi smjate ho aap mja aa gya !!!

  • @pradeepranjan8226
    @pradeepranjan8226 7 месяцев назад +2

    Jiska rank jyda hai wo papa banega😂😂 Love the way you explain

  • @souravjoshi2293
    @souravjoshi2293 Год назад +2

    These videos are masterpiece

  • @ShardulPrabhu
    @ShardulPrabhu 26 дней назад

    Thanks sir ❤

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak 7 месяцев назад

    great

  • @yashagarwal9784
    @yashagarwal9784 4 месяца назад +1

    BEST!

  • @JJ-tp2dd
    @JJ-tp2dd Год назад +1

    Wow bhai

  • @tanishchordia4813
    @tanishchordia4813 5 месяцев назад +4

    after learning from you , I can surely say that no one can make me understand the concepts better than you. I really wanna know or you can say very eager to know who taught you DSA . schme dil se lagta hai ki apse better dsa pure utube pe koi solve nhi kr skta. really wanna know ki apko kisne padhaya tha?

    • @tanishchordia4813
      @tanishchordia4813 5 месяцев назад +1

      ans nhi diya apne mik bhaiya?🥺

    • @codestorywithMIK
      @codestorywithMIK  5 месяцев назад +5

      Hello Tanish 🙏❤️
      Actually I am a self taught tutor.
      I never took any paid course. I studied everything from internet and from varied sources, books etc.
      I never even took Leetcode Premium membership 🤣🙈
      I really appreciate your kind words. I am so happy to connect with you people.
      Would love to have all of you under one roof where we all can talk and interact someday.
      Please remember, i am just like you. You can also solve these. Just keep practising. We all are on same level.
      Thanks again ❤️❤️🙏🙏

    • @codestorywithMIK
      @codestorywithMIK  5 месяцев назад +1

      I have mentioned your comment on my Instagram also. Thank you for making my day ❤️🙏

    • @tanishchordia4813
      @tanishchordia4813 5 месяцев назад +1

      @@codestorywithMIK Thank you for helping me to get the DSA fear out of me.❤

  • @oqant0424
    @oqant0424 8 месяцев назад

    U explained it so so well ☺
    Thanks from the bottom of my heart :)

  • @user-do1eq7tl3e
    @user-do1eq7tl3e Месяц назад

    basically , rank signifies the length of longest path from parent (root) to leaf node.
    so if rank[0] = 2 , that means there are 2 levels in tree path.

  • @pratyushtripathi1728
    @pratyushtripathi1728 Месяц назад +2

  • @piyushacharya7696
    @piyushacharya7696 Год назад +2

    Bro, you should also mention union by size as it is lot more intuitive than the rank one. BTW the content is gold😍

    • @codestorywithMIK
      @codestorywithMIK  Год назад +3

      Indeed. Actually the actual DSU mentions about rank and path compression. I have kept size in hold until I solve a Qn which will compel us to introduce size also. That will be intuitive and make us think that YES, That’s why we need size. Will post that qn soon
      Thanks again for your precious feedback ❤️❤️❤️

  • @aryanraj9235
    @aryanraj9235 Год назад +1

    addicted to your videos.❤

  • @kashishkashyap6229
    @kashishkashyap6229 11 месяцев назад +1

    how this can be so easy. great content!

  • @aswithasai4015
    @aswithasai4015 11 месяцев назад +1

    this explanation was so good union .please explain union by size too

    • @codestorywithMIK
      @codestorywithMIK  11 месяцев назад +1

      Thanks a lot.
      I will upload Union By size this weekend 😇🙏

  • @pranavpranjal2717
    @pranavpranjal2717 Месяц назад +2

    path compression is same like using dp

  • @oqant0424
    @oqant0424 8 месяцев назад

    19/41 done [6.11.23] ✅✅

  • @shauncrasta619
    @shauncrasta619 4 месяца назад

    Why only increase the rank when the ranks are equal? What if when doing a union, even if the rank of a node is less than the other, but it can be connected to a parent which is having a higher rank? How do we handle this? Pretty confusing.

  • @Gopal-lq5rm
    @Gopal-lq5rm 24 дня назад

    but bhaiya , hum toh path compression se agar height wali factor hata hi rhe hai , toh same time rank ka kya hi significance reh gya ?
    Thoda samjha do na pls

  • @rishabhsinha7033
    @rishabhsinha7033 Год назад +1

    Bhaiya.. Graph ke kuch questions Java me bhi solve kar dijiye!! Helpful hoga ❤️

    • @codestorywithMIK
      @codestorywithMIK  Год назад +1

      Sure Rishabh. I will try to provide java too.
      Also some people add java code in comments, i will PIN then in case i get it
      Thanks again for watching my videos

    • @rishabhsinha7033
      @rishabhsinha7033 Год назад +2

      @@codestorywithMIK Thanks for consideration, if you could provide java code in your style, with video, story and then code conversion, it will help a lot of folks..

  • @CodeZipper12
    @CodeZipper12 9 месяцев назад

    can you give me leetcode question no that you are talking about

  • @deepakdass4710
    @deepakdass4710 6 месяцев назад +2

    Graph count = 19

  • @madhavgupta2002
    @madhavgupta2002 Год назад +1

    kitne baje ayega sir, agar late ayega toh phir mai khudse karne ki koshish karunga pls btao time approx

    • @AryanTomar_2025
      @AryanTomar_2025 Год назад +6

      bro you should try yourself first , if you are not able to solve then see videos otherwise you would not able to think approach in interviews.

    • @codestorywithMIK
      @codestorywithMIK  Год назад +5

      Being uploaded. Little Length , youtube taking time to upload

  • @kartikeyavats
    @kartikeyavats 2 месяца назад +1

    jiska rank jyada hota h voo papa banta h ye hi bola tha maine apne dosto ko bhi 🤣🤣🤣🤣🤣

  • @fashionvella730
    @fashionvella730 8 месяцев назад +1

    are you in to competitive programming? if you are then please share your codeforces profile

    • @codestorywithMIK
      @codestorywithMIK  8 месяцев назад +1

      Hi there,
      Unfortunately No. i have not tried CP

  • @udaykumarchetla6205
    @udaykumarchetla6205 Год назад

    when to use dsu rank and size ?q

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      I would suggest always use rank and size compression in DSU. It’s an optimised version

    • @udaykumarchetla6205
      @udaykumarchetla6205 Год назад

      @@codestorywithMIK In yesterday's contest I used dsu union by size which worked but If i use by rank it's giving wrong answer. And can u upload a video on dsu union by size as it's lot more intuitive

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      I see. Now i got your qn.
      Yes yes, union by size and rank are different.
      I will upload a qn on dsu which will help explain dsu by size

    • @udaykumarchetla6205
      @udaykumarchetla6205 Год назад

      @@codestorywithMIK what's the difference in both?

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Let me create a video on it soon to deep dive into it

  • @everydaygkinhindi7583
    @everydaygkinhindi7583 Год назад +1

    can we have your socials Id's for help🙏

    • @codestorywithMIK
      @codestorywithMIK  Год назад +1

      Soon I will create. Will plan
      Thanks for the suggestion ❤️

  • @beenasatyendrapal6405
    @beenasatyendrapal6405 6 месяцев назад +1

    how you explain every thing so easily and nicely🥹🥹🥹🥹🥹