Prim's Minimum Spanning Tree Algorithm | Graph Theory

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

КОМЕНТАРІ • 64

  • @dannyfogel9156
    @dannyfogel9156 4 роки тому +33

    Thank you so much!!! learning algorithms from a book in the university is really hard and your videos are super helpful!!

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

      don't use my display picture please

    • @user-wc1sm8cj8s
      @user-wc1sm8cj8s 3 роки тому +2

      @@mechy6065 Is this a coincidence?? LOL

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

      @Kohen Kaden hmmmmmmmm

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

      exactly the same

  • @captain-ramen
    @captain-ramen 2 роки тому +5

    This explanation is so good! Understanding this algorithm is already hard, and coding the solution up is difficult on another level. I tried reading the code on different websites and in different videos, and I had a hard time understanding it. However, you example, visualization and clean code made me understand everything in less than 20 minutes. Thank you so much!!!

  • @ivansyabro7854
    @ivansyabro7854 13 днів тому

    Better explanation than Leetcode premium, thanks a lot!

  • @MykolaDolgalov
    @MykolaDolgalov 4 роки тому +23

    I'm so glad I found your channel! Thank you so much for your hard work!

  • @OllytheOzzy
    @OllytheOzzy 3 роки тому +2

    Hands down best channel for graph algorithms resource on youtube. Thanks mate

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

      Nope, Hands Up, You are under arrest😂😂 For saying the Truth..

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

    I have missed these videos so much. Awesome explanation.

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

    Thanks for making it super easy to understand. I am super lucky that I found your channel among the pile.

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

    This deserves more views.

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

    You're so good that i recommend your channel to every SWE i meet.

  • @joker345172
    @joker345172 3 роки тому +2

    This helped me a lot. Many thanks to you, my friend

  • @iam_kundan
    @iam_kundan 3 роки тому +2

    Excellent Explanation. It was crystal clear. I got everything in one go.

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

    Thank you @WilliamFiset for such an amazing explanation, I wish you were teaching while I was still in college.

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 місяці тому

    brilliant explanation = thank you so much

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

    Clean and excellent explanation
    Elegant & Beautiful

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

    thank for your video ,it help me learn Tree algorithm !!!

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

    Very Nice Bro. Keep on making videos on other topics. Your animations are really usefull.

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

    This helped me a lot! Thanks!

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

    Simple and helpful ✌🏻

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

    Thanks William! Understood the algo :)

  • @CodeCraftWithVinayak
    @CodeCraftWithVinayak 5 років тому +2

    Thanks williams

  • @nmamano
    @nmamano 4 роки тому +6

    3:27 to be more precise, the two versions (lazy and eager) have the same complexity of O(E*log V) because log(E) = O(log(V)). This is because E < V^2, so log(E) < log(V^2) = 2*log(V) = O(log V). In big-O notation, it never really makes sense to use log(E) instead of log(V) for graph algorithms.

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

      What about when there are O(V^2) edges? For example a dense or complete graph.

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

      @@amey7064 then both are O(V^2 log V).

  • @sk-nath
    @sk-nath 5 років тому +1

    It's very helpful. Thanks

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

    How will the complexity be E log E ? Is it for Adj list representation because for a matrix representation I am selecting a vertex then looping through all other vertices to add them in the queue, if an edge exists at all so I am doing the work V times right?
    So the complexity will still be O(V^2 )

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

    After watching people on the internet unnecessarily complicating this beautiful algorithm. I'm here!

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

    thank you so much !! Really helpful !

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

    Thanks for the explanation!

  • @beens3865
    @beens3865 9 місяців тому

    Thank you lots!!

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

    Well done!

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

    great job!!

  • @vijethkashyap151
    @vijethkashyap151 2 місяці тому

    Beautiful! :)

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

    pls explain the time and space complexity as well

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

    Thank you, Sir.

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

    Hey awsome video but I don't understand what happens at 8:41 you say its stale because (2,1,3) but how did you get that should'n it have been (1,2,3) because you were starting from node 1?

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

    very helpful!

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

    U'r the best man u'r the best

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

    For someone in doubt like myself, wondering which node to start from to put into priorityqueue, you can start with nay node and will still get the same MINIMUM SPANNING TREE (which by definition contains all nodes joined via the minimum weighted edges)

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

      Jatin Shashoo that’s right, except there may be multiple spanning trees

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

      yes, and all the trees weight cost the same

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

    Why choose vertex which is connected by minimum adge? it works even if we traverse and choose vertex from an ordinary queue(not priority queue)
    Becoz the goal is to connect vertex with minimum edge only and we can archive this even by choosing elements randomly

  • @99progers
    @99progers 4 роки тому +9

    Do you know what the scariest think in the world is >??

    • @astroash
      @astroash 3 роки тому +6

      No, and I don't even know how to reverse a linked list.

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

      not knowing how to invert a binary tree?

  • @DeepakKumar-ox5ti
    @DeepakKumar-ox5ti 4 роки тому

    Yes, Prims is nice.

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

    what does to poll mean? we just choose a node randomly?

    • @WilliamFiset-videos
      @WilliamFiset-videos  Рік тому +1

      Polling is the act of removing a node from the top of the priority queue. In the pseudocode in this video it's the equivalent of .dequeue()

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

      @@WilliamFiset-videos I see thank you

  • @1UniverseGames
    @1UniverseGames 2 роки тому

    Is each minimum-heavy spanning tree of N also a minimum spanning tree of N vertices!

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

    where in the code do we select the cheapest edge from the PQ?

    • @WilliamFiset-videos
      @WilliamFiset-videos  4 роки тому +1

      That's the line 'edge = pq.dequeue' at 13:14 which removes the next best edge from the priority queue.

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

      @@WilliamFiset-videos Hey. What would happen if i had a node with 2 Edges. The first one has a cost of 0 and the second a cost of 2. I follow the Edge with cost 0 and end up at a Node with another 2 Edges which all have higher edge costs than 2. If i dequeue i'd get the Edge from the first Element with cost 2 right? Would that change anything in the workflow?

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

      @@ikaros9727 You need to get to ALL the nodes in the graph anyway, so the workflow doesn't change. You always choose the cheapest edge and follow it to get the minimum spanning tree.

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

      the pq sorts based on the minimum edge cost,so it always dequeue the minimum edge

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

    I understand MST in 10 minutes while I spent long time in university book.

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

    why am i hearing "oh hell nah" in the background 5:20

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

    damn I thought 2:14 was about to be a swastika

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

    2:12 when i started doing it, it looked kinda sus bro hahahaha
    almost a nazi sign

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

    One minor thing: it seems mstEdges[0] stays null.