Graph Data Structure 4. Dijkstra’s Shortest Path Algorithm

Поделиться
HTML-код
  • Опубликовано: 21 ноя 2024

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

  • @daringdarius5686
    @daringdarius5686 4 года назад +916

    I don't know if you know this, and this is 4 years late, but this is one of the cleanest, easiest to understand video's (conceptually-wise) for Dijkstra's.
    I've seen several, but this! This is the best one. :)

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +82

      Great to hear! :)KD

    • @vijayalakshmi0714
      @vijayalakshmi0714 3 года назад +8

      @@ComputerScienceLessons lol, but i'm listening even now, best explanation. Keep it up

    • @eatbreathedatascience9593
      @eatbreathedatascience9593 2 года назад +3

      I agree fully. Best !

    • @tudorradu5848
      @tudorradu5848 2 года назад +2

      @@ComputerScienceLessons He's right! It was veryyy easy to understand. Thank you

    • @555aboud
      @555aboud 10 месяцев назад

      stunning, clear explanation. Thank you so much!!!

  • @adityapappu4963
    @adityapappu4963 4 года назад +153

    This is literally one of the cleanest, simplest, no-nonsense beautiful explanations of an algorithm I have ever watched on RUclips. Amazing. To-the-point. Crisp. And so easy to understand and digest. THANK YOU.

  • @assansanogo1343
    @assansanogo1343 8 лет назад +1330

    FINALLY SOME CLEAR STUFF. almost crying

  • @royazut550
    @royazut550 7 лет назад +268

    !!!finally a good and simple explanation
    oh tears of joy...
    may the gods bless you with bugless codes

    • @neelparekh9846
      @neelparekh9846 4 года назад +8

      "May the gods bless you with bug-less codes."
      I'm going to use that a lot.

    • @neptechbyte
      @neptechbyte 3 года назад

      haha epic comment bro

  • @reiniervanleeuwen9815
    @reiniervanleeuwen9815 5 лет назад +119

    This has to be the best explanation of Dijkstra's Shortest Path algorithm... Thanks a lot!

  • @ietskaag552
    @ietskaag552 4 года назад +5

    Seriously, I've been looking at so many pseudocodes and incomprehensible python scripts without any clear explanation on how the algorithm actually works. I salute you. This has helped me so much. I can't thank you enough.

  • @amine_fadssi
    @amine_fadssi Год назад +20

    The best video on the internet explaining the Dijkstra’s algorithm, thanks a lot sir.

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

    I haven't found a better tutorial than this for understanding and computing distances using Dijkstra's algorithm. Thank you so much.

  • @TANEM315
    @TANEM315 8 лет назад +15

    You sir are BY FAR the BEST teacher of algorithms on RUclips or anywhere else I've seen algorithm lectures. THANK YOU FOR POSTING THIS! With your well-paced, methodical style you could probably teach anything!!!!

  • @johnstorm589
    @johnstorm589 Год назад +9

    Even 6 years later, this is still the best explanation ever

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

    I can't believe how well done this video was made. I appreciate your hard work at a visual representation of this algorithm.

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

    This is by far the best video I've seen on this algorithm. It is clear and doesn't skip any steps.

  • @handalz
    @handalz 2 года назад +2

    Appreciate this video. Watched a number of others about Dijkstra's Algorithm and couldn't understand HOW and at what stage another path is evaluated. It wasn't until I saw the graph and how we can track the changes that it somehow brought the entire algorithm into crystal clear focus. Thanks!

  • @ComputerScienceLessons
    @ComputerScienceLessons  7 лет назад +85

    Hi FTP
    My scenario is for a non-directed graph (you can go backwards and forwards on any edge), so all the nodes can indeed be reached. However, for a directed graph, some nodes may be unreachable from the given start, as you have intimated. Dijkstra's algorithm finds the shortest paths only to the nodes that can be reached from the starting node. (if there is no path to a node from the start, it's irrelevant). The loop will end when all 'reachable' vertices have been visited. By the way, Dijkstra's algorithm doesn't work if the graph edges have negative weights.

  • @Monochones87
    @Monochones87 2 года назад +3

    Lovely, this has been the clearest explanation I've seen so far for Dijkstra's algo. Seriously, thank you so much!

  • @ronglass5968
    @ronglass5968 4 года назад +8

    The VERY clearest and well-paced explanation by far! Thanks!

  • @ammarulhassan5851
    @ammarulhassan5851 4 года назад +2

    After spending lots of time on other videos and stuff finally, I have understood "Dijkstra’s" Thanks to this LEGEND.

  • @matthewsattam1982
    @matthewsattam1982 7 лет назад +97

    Extremely clear, extremely well put together visually. Well done, and thank you.

  • @tartarus1322
    @tartarus1322 5 лет назад +13

    I wish I could upvote this more than once. It is honestly a brilliant, clear, and concise explanation

    • @ComputerScienceLessons
      @ComputerScienceLessons  5 лет назад +1

      You are very kind. Thanks. :) KD

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

      @@ComputerScienceLessons But really it's awesome video.. the best info in the least possible time.. Thank you so much from India 🥰

  • @rabiakhan7338
    @rabiakhan7338 3 года назад +1

    I've watched a lot of videos on this algorithm and let me tell you if you're watching this you are at the right place..
    and thank you so much Sir!

  • @jackych5055
    @jackych5055 4 года назад +6

    man this Dijkstra guy deserved a nobel prize for it

  • @mikelanigan9601
    @mikelanigan9601 5 лет назад +11

    I must commend the quality and clarity of this video: it is by far the best video I've seen on RUclips to date on the subject of explaining Dijkstra's Algorithm. There are so many other videos that do not deal with the problem of keep a record of the shortest route sufficiently systematically enough, in my opinion. This video is systematic, showing the use of a table to perform the algorithm very clearly. Instruction of this level is not accidental; my congratulations to those involved in its production and execution. You have done the domain of Computer Science the world of good. Keep up the great work!

  • @drowmik
    @drowmik 4 года назад +2

    I'm a programming lover man who have no computer science degree. I have seen many videos but this is the best and easiest way to explain the algo... Thanks a lot.. want more

  • @babakbekhradmanesh871
    @babakbekhradmanesh871 3 года назад +2

    Thanks for your extraordinary explanation. This is literally one of the simplest explanations of an algorithm I have ever watched on RUclips.

  • @selvalooks
    @selvalooks 6 лет назад +2

    i used to think this "Dijkstra’s Shortest Path Algorithm" is not for me to understand :) , now i can do it even getting from sleep after watching this video , thanks a ton !!!

  • @sanseverything900
    @sanseverything900 2 года назад +3

    Thank you for including the psuedo-code at the end. Really helped me get an idea of how I should structure my own code!

  • @alpharussel653
    @alpharussel653 2 года назад +1

    An entire computer science degree courses embedded in this amazing channel. Thank you. Not all heroes wear a cap.

  • @SouravendraKrishnaDeb
    @SouravendraKrishnaDeb 5 лет назад +564

    We won't be visiting A, again.
    Me: CRIES LOUDLY

  • @Aca99100
    @Aca99100 5 лет назад +2

    I have never seen a video with such clear and step-by-step explanations. Good job here!

  • @canmalatyaloglu8690
    @canmalatyaloglu8690 4 года назад +3

    The fact that this explanation of Dijkstra's is way more easily understandable and to-the-point than the one Computerphile has is astounding. Slides ftw

  • @lewistian7975
    @lewistian7975 5 лет назад +13

    BEST explanation of Dijkstra's algorithm EVER!

  • @Moggery
    @Moggery 2 года назад +5

    Fantastically clear and concise. Makes my revision an absolute dream, I can’t thank you enough. 10/10

  • @mikefriedman9573
    @mikefriedman9573 5 лет назад +20

    Absolutely the best explanation. Cleared up any and all lingering questions in my mind.

  • @virendrabhati6685
    @virendrabhati6685 3 года назад +1

    When I was doing MCA noone explain us in such a simple way...... Now it's so easy after this video... thanks for your kind information....

  • @aquilazyy1125
    @aquilazyy1125 4 года назад +5

    This is very enlightening. I’ve come up with a similar algorithm myself that uses a simple width-first or depth-first search, but I’ve never thought of that we should first calculated the vertex with the least known distance! Thanks for sharing it.

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +2

      Don't thank me, thank this guy :)KD
      en.wikipedia.org/wiki/Edsger_W._Dijkstra

  • @andresnieves9018
    @andresnieves9018 6 лет назад

    If you can't explain it simply, you don't understand it well enough. Beautifully done. Thank you!

  • @hadeneh
    @hadeneh 6 лет назад +170

    I signed in just to like this video.

  • @SpaceDisco1
    @SpaceDisco1 5 лет назад +6

    It's really interesting, how sometimes one thorough example can clear up everything.

  • @Museko
    @Museko 7 лет назад +39

    I'm watching a bunch of your videos to review for my Algorithms exam. Thanks a bunch for making these!

    • @ComputerScienceLessons
      @ComputerScienceLessons  7 лет назад +6

      Thanks for the comment. It's good to hear you're finding them useful. :)

  • @Jack-hd3ov
    @Jack-hd3ov 4 года назад +1

    After watching about 5 videos on this algorithm, yours has made it crystal clear. Thank you.

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +1

      You're very welcome. :)KD

    • @Jack-hd3ov
      @Jack-hd3ov 4 года назад

      @@ComputerScienceLessons Your A* explanation is also the best I found

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

    This explanation is by far the Best I've seen.. This is crystal clear , thank you very much!

  • @lawrencedennison-hall9642
    @lawrencedennison-hall9642 4 года назад +8

    Such a clear and coherent explanation. Watched the Craig n Dave video on this previously but this is such a clearer explanation. Understand this now cheers!

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +2

      Glad you found it useful. There is nevertheless some good stuff on Craig n Dave's channel :)KD

  • @q1chen
    @q1chen 3 года назад

    This 10mins video >>> 45mins video from my lecturer. LEGEND🙏

  • @nitesh4146
    @nitesh4146 2 года назад

    This is the best video on Dijstra's Shortest path algorithm I have viewed on RUclips. Kudos!

  • @ayasswain
    @ayasswain 7 лет назад

    The best video on shortest path algorithm on RUclips. Some of other videos that comes at the top of the search result are crap. People have unnecessarily complicated the explanation.

  • @markh1791
    @markh1791 2 года назад

    The clearest, and most succinct, explanation of Dijkstra's algo I've seen. Thanks!

  • @leox8888
    @leox8888 3 года назад +4

    Really appreciate this video. As a network engineer, i have read many book about how SPF works but this one is the best. And i can also develop the code based on this video. One thing I was stuck for a while is when having the directed graph (shorted path), it is a bit tricky to print all the shortest path considering ecmp case.

  • @m_t_t_
    @m_t_t_ 2 года назад +2

    Thanks for actually including the way to find the shortest path between the start node and a certain node, alot of tutorials leave that out

  • @ice_cube918
    @ice_cube918 3 года назад +1

    This is the best explanation of Dijkstra's algorithm I have seen!! I especially like the last summary part.

  • @Satharus
    @Satharus 5 лет назад +4

    Thank you!
    This is the single best video explaining the algorithm on RUclips.

  • @leonidsukharnikov2563
    @leonidsukharnikov2563 4 года назад

    Perfect video! Clear examples, understandable English and ... no profanity.

  • @5he1tied
    @5he1tied 5 лет назад +3

    This is the fourth video I had to watch. Only one that explains clearly, thanks.

  • @JamshadAhmad
    @JamshadAhmad 4 года назад +3

    This video is a definition of precise and concise explanation. Thank you very much.

  • @timuralmamedov1900
    @timuralmamedov1900 6 лет назад +3

    Great explanation! Finally, I understood it. The table really helps to not get lost. Thank you so much!

  • @chrise202
    @chrise202 5 лет назад +1

    You know this is the best illustration and guideline for implementing it on youtube.

  • @KevinIaMmE94
    @KevinIaMmE94 4 года назад +2

    I had to watch this video two times in order to grasp the concept. Thank you!!

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +1

      You are very welcome. I get my students to check their understanding by working through the algorithm with a different graph. :)KD

  • @whiningmachine
    @whiningmachine 2 года назад

    Fantastic explanation. Indeed, it's the best, clearest, simplest, and most useful resource by far that I've found after hours of searching. Thanks for making it!

  • @danpang9213
    @danpang9213 3 года назад +1

    I am just captivated by the appealing spoken English

  • @mingxie3877
    @mingxie3877 2 года назад

    It's the clearest explaination for Dijkstra I have seen before. Here is my test code for java according to your lecture. Just a litte complicated to build the model which you present in video.
    import java.util.ArrayList;
    import java.util.List;
    public class Dijkstra {
    public static void main(String[] args){
    List vertexList = buildVertexs();
    // a weight or distance matrix to present vertex to other vertex if they are adjacent,
    // else if they are not adjacent mark as -1
    int[][] matrix = new int[vertexList.size()][vertexList.size()];
    matrix[0]= new int[]{0, 6, -1, 1, -1};// a-a->0,a-b->6,a-c->-1(no neighbor relation),a-d->1, a-e->-1
    matrix[1]= new int[]{6,0,5,2,2};//b-a->6,b-b->0,b-c->5,b-d->2, b-e->2
    matrix[2]= new int[]{-1,5,0,-1,5};// c-a->-1(no neighbor relation),c-b->5,c-c->0,c-d->-1(no neighbor relation),c-e->2
    matrix[3]= new int[]{1,2,-1,0,1};// d-a->1,d-b->2,d-c->-1(no neighbor relation),d-d->0,d-e->1
    matrix[4]= new int[]{-1,2,5,1,0};// e-a->-1(no neighbor relation),e-b->2,e-c->5,e-d->1,e-e->0
    List result =findDijkstra(matrix,vertexList);
    for(Vertex v: result){
    System.out.println("A to "+v.getName()+" shortest path is "+v.getShortPath());
    }
    }
    public static List findDijkstra(int[][] weightMatrix, List vertexList){
    List visitStatus = new ArrayList();
    while(visitStatus.size()!Vertex.isVisited())).min((Vertex::compareTo)).get();
    int index = vertexList.indexOf(current);
    for(int i=0; i

  • @ayasswain
    @ayasswain 7 лет назад +1

    Wonderfully explained. The best video i have come across so far on Djikstra's Algorithm.

  • @ahmedsaid8180
    @ahmedsaid8180 2 года назад +1

    Thank you very much! I have been trying understand this algorithm for 5 hours and I finally got it now "thanks to you"!

  • @JaffarBrar
    @JaffarBrar 5 лет назад +7

    Crying in disbelief 😭😭. Finally some clear explanation. Thank youuuuu

  • @Amitielle666
    @Amitielle666 7 лет назад +163

    Finally a video explaining IT stuff without nearly not understandable indian accent!

  • @lolking420
    @lolking420 4 года назад +1

    This is the best explanation for Dijkstra's shortest path. Thank you so much

  • @TourGuideFTW
    @TourGuideFTW 7 лет назад +5

    The way you explained the algorithm was just great, thanks a lot for making this video!

  • @GavinLon
    @GavinLon 5 лет назад +4

    This is a great video. You have provided a very simple but clear explanation.

  • @MinecraftLetstime
    @MinecraftLetstime 6 лет назад +4

    By far the best video for explaining this algorithm! Perfect.

  • @MimicalThought
    @MimicalThought 7 лет назад +1

    We are learning about Dijkstra's Shortest Path in my Data Communications course and this video explains the algorithm much more clearly than my professor had attempted to explain in our lecture video / notes. Thank you very much, in just 10 minutes I was able to understand something I was spending 30-60 minutes on. Well done!! :)

  • @supernenechi
    @supernenechi 3 года назад +3

    You explained this so incredibly clearly! It's really not that hard at all! Thank you so much!

  • @tranpaul4550
    @tranpaul4550 3 года назад +1

    Le me cry of joy because I find this absolute gem to prepare for the final.

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 года назад +2

      Delighted to help. Remember, Dijkstra's is a greedy algorithm. It always selects the nearest node next, on the assumption that this will ultimately lead to the shortest overall path. It's common for an examiner to ask you to compare Dijkstra's algorithm with the A* algorithm . Good luck :)KD

    • @tranpaul4550
      @tranpaul4550 3 года назад +1

      @@ComputerScienceLessons Wow man, my teacher did asked the question to compare Dijkstra's algorithm with the A* algorithm and Bellman-Ford. You are a god. Btw love your new series and waiting for more

  • @Satharus
    @Satharus 5 лет назад +2

    This is the single best and most simple explanation of Dijkstra's algorithm. It saved me multiple times.
    Thank you so much.

  • @miller5565
    @miller5565 3 года назад +2

    I couldn’t have asked for a clearer video, thank you sir.

  • @mmfawzy4850
    @mmfawzy4850 4 года назад +1

    you are such great story teller, to learn algorithms as a story is fantastic, please continue ...

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +1

      Thanks for the lovely comment. I working on some new videos at the moment.

    • @mmfawzy4850
      @mmfawzy4850 4 года назад

      @@ComputerScienceLessons Go on boss

  • @theobserver4794
    @theobserver4794 4 года назад +1

    two hours of a boring lecture vs 10mins cool explanation. thanks mate

  • @DentrifixoRam88
    @DentrifixoRam88 6 лет назад

    Hi from Argentina. After watching 4 other videos I can say this is the best explained solution steps I've found so far. Thanks!!

  • @tundet8963
    @tundet8963 7 лет назад +2

    Excellent work, Clarity, and explanation at all stages. Thanks, keep up the good work

  • @rickyc1991
    @rickyc1991 4 года назад +2

    Thanks to your clear explanations, I won't be visiting this video again.
    Maybe just once more before the finals.

  • @vinferothas
    @vinferothas 3 года назад +1

    I had closed the tab after watching video. Just remembered and came back to give a like. Great video

  • @forestpfeiffer1370
    @forestpfeiffer1370 4 года назад +3

    Finally, an example that makes sense, wonderful job!

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

    Tomorrow I have my exams on this topic.. This is the best video about djkstras algorithm on whole internet

  • @Jukebox300Minecraft
    @Jukebox300Minecraft 11 месяцев назад

    Wow it's an honor to be learning this from Computer Science itself

  • @kandy5983
    @kandy5983 4 года назад +1

    u r king of simple and clear explanation

  • @dawnjinx4962
    @dawnjinx4962 4 года назад +2

    I FINALLY UNDERSTAND THANK YOU SO MUCH!!!!
    This was the most concise and easy to follow video I've managed to find on this algorithm

    • @ComputerScienceLessons
      @ComputerScienceLessons  4 года назад +1

      You are most welcome. I usually ask my students to check their understanding by working through it with a different graph. :)KD

  • @nathanriches9547
    @nathanriches9547 2 года назад

    Thanks James May. This was a great episode of Top Gear

  • @WhiteEyeTree
    @WhiteEyeTree 7 лет назад +3

    Slight correction: this algorithm is not greedy! Yes, it jumps to the local optimum at every step but it also goes back and updates any decision that it has already made in previous iterations. A truly greedy algorithm would just run towards the "closest" neighbour that he hasn't already visited, most probably finding himself forced to run down an stupidly costly edge.
    Other than that, wonderful video!

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

    So easy to follow. Best video I’ve seen on this algorithm

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

    This video is a game changer. Understood it in one shot. Brilliant!

  • @amskumar
    @amskumar 5 лет назад +3

    Best video on Dijkstra I've seen so far. Thanks for doing it with so much clarity.

  • @comcfi
    @comcfi 4 года назад

    I will recommend a Nobel prize for you for this explanation

  • @ccidral
    @ccidral 4 года назад +3

    I absolutely, unquestionably agree that rigorous math definition is important and necessary for this kind of stuff. That said, why do most math/cs book authors are so TERRIBLE at teaching? To the point that you have to spend gold on a number of expensive books in a desperate attempt to learn one thing well. I mean, feel free to lay out the rigorous math stuff, I know that's important, but please please PLEASE also give us a decent, understandable, not-vaguely-abstract translation of that stuff.
    Awesome video by the way! Thanks so much.

  • @ddddchannel837
    @ddddchannel837 4 года назад +1

    Extremely clear and well thought out video. Thanks for uploading!

  • @ThewOrldIssqUare
    @ThewOrldIssqUare 4 года назад +2

    Thanks for this! As others have said, this is one of the clearest explanations on youtube!

  • @hanbrianlee
    @hanbrianlee 5 лет назад +5

    Omg.. out of like 10 dijkstra vids i attempted to eatch this is the best

  • @javadsabbagh8939
    @javadsabbagh8939 6 лет назад +4

    Thank you, Kevin. Very understandable and clear.

  • @danielm7755
    @danielm7755 3 года назад +2

    You've just earned yourself a new subscription champ! Great video! I love it!

  • @TheSmileyface103
    @TheSmileyface103 3 года назад +1

    Thanks a lot man, this cleared a lot of confusion related to this algorithm. May you be blessed with bugless code!

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 года назад +1

      You're very kind - but as I tell my students, you will learn more if your code doesn't work first time :)KD

    • @TheSmileyface103
      @TheSmileyface103 3 года назад

      @@ComputerScienceLessons hahaha fair point.

  • @josephantoniou3778
    @josephantoniou3778 2 года назад +1

    This is the best concise explanation I found. Thanks

  • @LeodSMW
    @LeodSMW 5 лет назад +2

    At 4:01 it struck me how this is going to work and how clever it is. Really neat!

  • @victorpopa8724
    @victorpopa8724 4 года назад +1

    Thank you, sir. Thank you. Finally someone that can make it clear for a min span tree

  • @ulfinawakjira1977
    @ulfinawakjira1977 3 года назад

    This is by far the best video I've seen on this subject it made implementation very easy and the explanation is the best I've ever seen so thank you very much!