Prim's Algorithm - Graphs | Minimum Spanning Tree(MST) in Graphs | Code and Implementation

Поділитися
Вставка
  • Опубліковано 11 жов 2024
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we explain the Prim's algorithms used to find the minimum spanning tree in a graph. We also explain about spanning trees in graphs followed by the implementation and code of this algorithm in a problem where:
    1. You are given a graph and a source vertex. The vertices represent computers and the edges represent length of LAN wire required to connect them.
    2. You are required to find the minimum length of wire required to connect all PCs over a network. Print the output in terms of which all PCs need to be connected, and the length of wire between them.
    For output, check the video.
    For a better experience and more exercises, VISIT: www.pepcoding....
    #graphs #prims #spanningtree
    Have a look at our result: www.pepcoding....
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education
    Join us on Telegram: t.me/joinchat/...

КОМЕНТАРІ • 79

  • @vikashgupta3305
    @vikashgupta3305 3 роки тому +50

    @ 9:14, He is such a awesome teacher agar ye chahte toh bolskte the ki video rewind Krke fir se dekhlo but he did the same dryRun again ❤️.
    Respect ++🙏

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

    I was not able to understand why we used Prims instead of Dijkstra, but at @ 16:48 he told to find difference in answers if graph was different and when I did it the confusion went away, he is by far the best teacher for learning DSA that too FREE. Hats off to you sir.

  • @tusharmahajan7754
    @tusharmahajan7754 3 роки тому +14

    if someone still confused in difference between dijkstra and prim. In prim you have to cover all the vertices but in dijkstra its not necessary. Solve the last graph with 25 weight sir gave it will be cleared.

  • @shanmukhchandrayama8508
    @shanmukhchandrayama8508 3 роки тому +16

    This is the best video on youtube for prims, really thrilled on knowing

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

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

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

    Best Explanation of prims ever found on you tube!!

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

      Glad it was helpful. Keep learning, Keep growing and keep loving Pepcoding!😊

  • @alpishjain1317
    @alpishjain1317 3 роки тому +10

    sir please upload advance graph playlist also i have completed the whole playlist and i just love your teaching.

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

      Let's do some practice together ,share good questions with me on my whatsapp haha😂😂😂😂

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

      Which language do you prefer ?
      Java.

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

    Are bhai bhai bhai bhai!!!!!!!!!!!!!!!!!!!!!!! . Sir you are Legend in the field of DS Algo. You can make any algorithm simple , and also you are the USP of pepcoding , so I would request you to continue making DS videos.

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

      Thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

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

    With Prim's algorithm we find minimum cost spanning tree. The goal is to find minimum cost to cover all nodes.
    with Dijkstra we find Single Source Shortest Path. The goal is find the shortest path from the source to every other node

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

    Have seen other videos too of the same concept.... but so far this is the best explanation of this problem.. 👍👍

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

    best explanation available on youtube

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

    Difference in the answer if we consider the question given at 17:05
    Dijkstra- reaching 6 would take 0346 or 03456
    Prims- reaching 6 would take 0123456

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

    Great content sir🙏. Typo in the thumbnail of this one.

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

    Thank you crystal explaination

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

    Thanks, ..very simple approach used compare to other solutions available on yt

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

    Beautifully explained !

  • @ASHISHSINGH-gs3yt
    @ASHISHSINGH-gs3yt 2 роки тому +1

    Such a simple and amazing implementation of prims. This is what i had in my mind but thought i was wrong because everyone was using 3 vector for some reason. Thanks thank you again.

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

    Bhot badiya vedio ..your channel will be so successful. The way you teach is simply awsome

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

      Glad you liked it!
      For better experience, visit nados.io, where you will get well curated content and career opportunities.

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

    Very Nicely Explained!

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

      Glad it was helpful! For more content like this please visit nados.pepcoding.com

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

    That was too awesome! Thanks for the content sir

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

    Sir you are awesome
    And your way of teaching is feel like i am listening this in front of you 🔥

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

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    Please cover flyod warshall also.

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

    Great Explanation. Thank you sir

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

    Bhaiya, can you upload more graph related algorithms like Kruskal's and Bellman Ford's.. etc.?

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

    Amazing video

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

    Sir pelease make more videos on algorithms and data structures asked in Mnc interviews🙏🙏

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

    Why does it give TLE on gfg even though if we are doing a BFS,
    I GUESS we are marking visited while popping instead of pushing ,
    Are we doing a lot of extra work in rm*wa*?

  • @ditu-kunalsarda6863
    @ditu-kunalsarda6863 4 роки тому +1

    SIr! If the vtces (4--6) had a weight of 5 then for minimum spanning (4-6) vtces should have been selected but from this code it wont be selected.
    It will still take the (4-5) and (5-6) path

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

      4-6 does not include vertex 5. That's why

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

      Check your code for Dijkstra's it will work fine but here in prims it checks for the minimum edge weight by not taking previous weights for comparison, so in this question, the shortest distance to 6 will be comparing it with the min(5--6, 4--6) which will be 5--6.

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

    @Pepcoding Graphs ki bhi porri playlist daal do youtube pe. Itna kar diya toh thoda or, please

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

    Sir please upload dynamic programming adv wale ques , final year walo Ka bhala ho jayega

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

      beta foundation ke graphs ka last video bna rha hun. aj he levelup shuru hoga.

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

      @@Pepcoding Sir graphs k level up k vidoes ka link kahan hai?

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

    Sir, Can you please tell us what is the time complexity of this prim's algorithm code?

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

    MST without source, then we'll traverse from 0 to n-11 nodes. In gfg it's showing TLE. Sir please upload optimized way of prim's

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

    sir please kruskals pe bhi video banao

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

    Sir MySQL and SQL ke lecture suggest kar dijiye jo apki tarah padata ho.

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

    Thank you so much sir

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

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like my efforts, I request a review
      g.page/Pepcoding/review?rc

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

      @@Pepcoding already done sr

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

    maza aa gaui

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

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    Please cover "circle of strings" on geeksforgeeks

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

    Sir, Bellman Ford or Kruskal's jaroori hain?

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

    hi sir
    isko 2D matrix me input leka sove karna hua toh kaise karnege ...jaisa input leetcode aur gfg pe diya hua hai

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

      usko adjacency list me convert karo

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

    Hi Sumit, please do make video on Kruskal's Algo. Already made video is really poor. Please help

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

      Feedback taken, for better experience and well organised content sign up on nados.io and start learning.

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

    saare topics miljate hain is channel par :)

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

      Thank you so much and If you like the content could you post something on LinkedIn about us? This will help us in reaching out to more people and help a lot of other students as well
      Something like this
      Sumeet Malik from Pepcoding is making all his content freely available to the community
      You can check it out here - www.pepcoding.com/resources
      /
      Also, this is the youtube channel - ua-cam.com/users/Pepcodingplaylists?view_as=subscriber

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

    To get placement kis hisab sa mujha serial vise video dekhni chahiya .I have no knowledge about it .pls guide me I have passed class 12.

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

      This is the proper to do these questions
      www.pepcoding.com/resources/online-java-foundation

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

      Thnk you sir

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

    time complexity kyu nai samjai sir :(((

  • @VijayKumar-bj8pe
    @VijayKumar-bj8pe 4 роки тому +1

    I have two doubts
    1) what is the time complexity of this algo?
    2) which is better, prims or kruskal?

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

      i think complexity is same as that of dijkstra elogv

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

      1.Time -O(vertices + edges)
      Space - O(vertices)

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

    Sir kruskal pe bhi question kara dijie

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

    koi sir ki videos ke notes bna rha hai kya? agar haa toh please reply

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

    can you provide a C++ code for this ?

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

    Basically primes is more greedy.

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

    this concept is not applicable on some other question
    we are not able to solve other question using this concept

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

    Anayatha 🙂

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

      Visit - nados.pepcoding.com and sign up to NADOS.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

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

    Sir Kruskals algo ki video kidhar hai ?

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

      beta foundation prims pe khatam kar dia. Level2 ke graphs mei daalunga kruskals. Wo thoda padhane mei samjhane mei jyada time leti hai

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

      @@Pepcoding Sir thode aur acche questions daaliye,bhut shi pd rhe ho aap,mze aa jaate he,aur bilkul bhi bhulne nhi dete aap phle ka,bhut baar revise kra dete ho. Thanks for all this.