Prim's Minimum Spanning Tree Algorithm | Graph Theory

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 KZread:
www.udemy.com/course/graph-th...
Algorithms repository:
github.com/williamfiset/algor...
Video slides:
github.com/williamfiset/Algor...
Personal website:
www.williamfiset.com

Пікірлер: 63

  • @adist98
    @adist985 жыл бұрын

    I have missed these videos so much. Awesome explanation.

  • @MykolaDolgalov
    @MykolaDolgalov4 жыл бұрын

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

  • @captain-ramen
    @captain-ramen Жыл бұрын

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

  • @anindyasur5070
    @anindyasur50702 жыл бұрын

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

  • @joker345172
    @joker3451723 жыл бұрын

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

  • @neshant89
    @neshant89 Жыл бұрын

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

  • @OllytheOzzy
    @OllytheOzzy3 жыл бұрын

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

  • @joydeepdas8632

    @joydeepdas8632

    2 ай бұрын

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

  • @dannyfogel9156
    @dannyfogel91564 жыл бұрын

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

  • @mechy6065

    @mechy6065

    3 жыл бұрын

    don't use my display picture please

  • @user-wc1sm8cj8s

    @user-wc1sm8cj8s

    3 жыл бұрын

    @@mechy6065 Is this a coincidence?? LOL

  • @gtab1268

    @gtab1268

    3 жыл бұрын

    @Kohen Kaden hmmmmmmmm

  • @Akiruu_Sama

    @Akiruu_Sama

    2 жыл бұрын

    exactly the same

  • @abijithbahuleyan785
    @abijithbahuleyan7854 жыл бұрын

    This deserves more views.

  • @ragibhussain5257
    @ragibhussain52574 жыл бұрын

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

  • @DanielSColao
    @DanielSColao3 жыл бұрын

    This helped me a lot! Thanks!

  • @HiteshSethiya
    @HiteshSethiya2 жыл бұрын

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

  • @sk-nath
    @sk-nath5 жыл бұрын

    It's very helpful. Thanks

  • @irulam4116
    @irulam41163 жыл бұрын

    Thanks for the explanation!

  • @mohammedsamir5142
    @mohammedsamir5142 Жыл бұрын

    Clean and excellent explanation Elegant & Beautiful

  • @baidya87
    @baidya874 жыл бұрын

    thank you so much !! Really helpful !

  • @iam_kundan
    @iam_kundan3 жыл бұрын

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

  • @sepehrkhodadadi9403
    @sepehrkhodadadi94033 жыл бұрын

    Simple and helpful ✌🏻

  • @CuriousAnonDev
    @CuriousAnonDev Жыл бұрын

    Thanks William! Understood the algo :)

  • @BullishBuddy
    @BullishBuddy4 жыл бұрын

    great job!!

  • @sallaklamhayyen9876
    @sallaklamhayyen987611 күн бұрын

    brilliant explanation = thank you so much

  • @nmamano
    @nmamano4 жыл бұрын

    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 жыл бұрын

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

  • @nmamano

    @nmamano

    3 жыл бұрын

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

  • @jagritbhupal5836
    @jagritbhupal58364 жыл бұрын

    Thank you, Sir.

  • @Chichichifan
    @Chichichifan3 ай бұрын

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

  • @CodeCraftWithVinayak
    @CodeCraftWithVinayak5 жыл бұрын

    Thanks williams

  • @yasharthgupta9002
    @yasharthgupta90022 жыл бұрын

    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 )

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

  • @briannguyen5057
    @briannguyen50573 жыл бұрын

    very helpful!

  • @rajkhoiwal4901
    @rajkhoiwal49012 жыл бұрын

    pls explain the time and space complexity as well

  • @beens3865
    @beens38656 ай бұрын

    Thank you lots!!

  • @vijethkashyap151
    @vijethkashyap15114 күн бұрын

    Beautiful! :)

  • @darthvader_
    @darthvader_2 жыл бұрын

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

  • @alihashemian3418
    @alihashemian34183 жыл бұрын

    U'r the best man u'r the best

  • @vinayak6564
    @vinayak65642 жыл бұрын

    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
    @chepaiytrath3 жыл бұрын

    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 жыл бұрын

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

  • @barry8871

    @barry8871

    3 жыл бұрын

    yes, and all the trees weight cost the same

  • @1UniverseGames
    @1UniverseGames2 жыл бұрын

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

  • @DeepakKumar-ox5ti
    @DeepakKumar-ox5ti4 жыл бұрын

    Yes, Prims is nice.

  • @anyadavidovich1083
    @anyadavidovich10834 жыл бұрын

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

  • @WilliamFiset-videos

    @WilliamFiset-videos

    4 жыл бұрын

    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

    Жыл бұрын

    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
    @diwu70912 жыл бұрын

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

  • @99progers
    @99progers3 жыл бұрын

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

  • @astroash

    @astroash

    3 жыл бұрын

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

  • @mechy6065

    @mechy6065

    3 жыл бұрын

    not knowing how to invert a binary tree?

  • @aliakseibadnarchuk
    @aliakseibadnarchuk5 ай бұрын

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

  • @TheDjarto
    @TheDjarto3 жыл бұрын

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

  • @aleksajovanovic5142
    @aleksajovanovic514211 ай бұрын

    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.