Prim's Minimum Spanning Tree Algorithm | Graph Theory

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 มิ.ย. 2024
  • Prim's Minimum Spanning Tree Algorithm
    Support me by purchasing the full graph theory course on Udemy which includes additional problems, exercises and quizzes not available on TH-cam:
    www.udemy.com/course/graph-th...
    Algorithms repository:
    github.com/williamfiset/algor...
    Video slides:
    github.com/williamfiset/Algor...
    Personal website:
    www.williamfiset.com

ความคิดเห็น • 63

  • @captain-ramen
    @captain-ramen ปีที่แล้ว +3

    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!!!

  • @adist98
    @adist98 5 ปีที่แล้ว +5

    I have missed these videos so much. Awesome explanation.

  • @anindyasur5070
    @anindyasur5070 2 ปีที่แล้ว +1

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

  • @MykolaDolgalov
    @MykolaDolgalov 4 ปีที่แล้ว +22

    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 หลายเดือนก่อน

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

  • @joker345172
    @joker345172 3 ปีที่แล้ว +2

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

  • @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

  • @neshant89
    @neshant89 ปีที่แล้ว

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

  • @abijithbahuleyan785
    @abijithbahuleyan785 4 ปีที่แล้ว +3

    This deserves more views.

  • @HiteshSethiya
    @HiteshSethiya 2 ปีที่แล้ว

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

  • @ragibhussain5257
    @ragibhussain5257 4 ปีที่แล้ว +3

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

  • @iam_kundan
    @iam_kundan 3 ปีที่แล้ว +2

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

  • @DanielSColao
    @DanielSColao 2 ปีที่แล้ว +1

    This helped me a lot! Thanks!

  • @mohammedsamir5142
    @mohammedsamir5142 ปีที่แล้ว

    Clean and excellent explanation
    Elegant & Beautiful

  • @sk-nath
    @sk-nath 5 ปีที่แล้ว +1

    It's very helpful. Thanks

  • @irulam4116
    @irulam4116 3 ปีที่แล้ว

    Thanks for the explanation!

  • @CuriousAnonDev
    @CuriousAnonDev ปีที่แล้ว

    Thanks William! Understood the algo :)

  • @baidya87
    @baidya87 3 ปีที่แล้ว +1

    thank you so much !! Really helpful !

  • @sepehrkhodadadi9403
    @sepehrkhodadadi9403 3 ปีที่แล้ว +1

    Simple and helpful ✌🏻

  • @Chichichifan
    @Chichichifan 3 หลายเดือนก่อน

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

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 วันที่ผ่านมา

    brilliant explanation = thank you so much

  • @CodeCraftWithVinayak
    @CodeCraftWithVinayak 5 ปีที่แล้ว +2

    Thanks williams

  • @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 )

  • @jagritbhupal5836
    @jagritbhupal5836 4 ปีที่แล้ว

    Thank you, Sir.

  • @BullishBuddy
    @BullishBuddy 4 ปีที่แล้ว +1

    great job!!

  • @MalachiBurke
    @MalachiBurke ปีที่แล้ว

    Well done!

  • @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?

  • @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).

  • @briannguyen5057
    @briannguyen5057 3 ปีที่แล้ว

    very helpful!

  • @beens3865
    @beens3865 6 หลายเดือนก่อน

    Thank you lots!!

  • @vijethkashyap151
    @vijethkashyap151 5 วันที่ผ่านมา

    Beautiful! :)

  • @rajkhoiwal4901
    @rajkhoiwal4901 2 ปีที่แล้ว

    pls explain the time and space complexity as well

  • @alihashemian3418
    @alihashemian3418 3 ปีที่แล้ว

    U'r the best man u'r the best

  • @darthvader_
    @darthvader_ 2 ปีที่แล้ว

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

  • @DeepakKumar-ox5ti
    @DeepakKumar-ox5ti 4 ปีที่แล้ว

    Yes, Prims is nice.

  • @1UniverseGames
    @1UniverseGames 2 ปีที่แล้ว

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

  • @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

  • @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

  • @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

  • @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

  • @diwu7091
    @diwu7091 2 ปีที่แล้ว

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

  • @99progers
    @99progers 3 ปีที่แล้ว +8

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

    • @astroash
      @astroash 3 ปีที่แล้ว +5

      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?

  • @aliakseibadnarchuk
    @aliakseibadnarchuk 4 หลายเดือนก่อน

    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 11 หลายเดือนก่อน

    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.