Graphs: Dijkstra's Algorithm

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024
  • How to find least-cost paths in a graph using Dijkstra's Algorithm.
    This video is distributed under the Creative Commons Attribution 2.5 Canada License.
    creativecommons...

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

  • @thodap1
    @thodap1 9 ปีที่แล้ว +57

    Excellent explanation, I just passed an exam because of this video, god bless you!

  • @kingofwebguru
    @kingofwebguru 10 ปีที่แล้ว +17

    Short and easy to understand. Great job.
    Hate books that spend pages over pages that make you want to burn it all.

  • @ArwensarYunikoCreations
    @ArwensarYunikoCreations 8 ปีที่แล้ว +174

    you explained 1 semester in 10 minutes

    • @dvorak2676
      @dvorak2676 7 ปีที่แล้ว +7

      what school and what year ?? wtf

    • @ammadahmed8811
      @ammadahmed8811 7 ปีที่แล้ว +14

      30 minutes of my Data Structures and Algorithms lectures. I think you belongs to mid of 20th Century

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

      fuck your school then

    • @tianyuchen1802
      @tianyuchen1802 7 ปีที่แล้ว

      We just explained that for 30 minutes,elps...

    • @ashishnegi3848
      @ashishnegi3848 7 ปีที่แล้ว

      is it so?? advanced?
      we are studying this in our 3rd sem and it comes of only 8-10 marks...it's an average level of problem.

  • @Athanazeus
    @Athanazeus 10 ปีที่แล้ว +86

    that's how you squeeze an hour of course into 10 mins

  • @mostafaeldeep7539
    @mostafaeldeep7539 8 ปีที่แล้ว +6

    Thanks alot man
    I passed my exam last year because of this video , thanks from egypt .

  • @Vineyverma
    @Vineyverma 10 ปีที่แล้ว +10

    Very well explained. Explaining complex things so easy is really an art. You are an artist. Thank you and Good wishes to you.

  • @4ourTimber
    @4ourTimber 10 ปีที่แล้ว +11

    Explained much better than my lecturer! Thanks!

  • @joetron5114
    @joetron5114 12 ปีที่แล้ว

    This is the best explanation for Dijkstra's that I have seen on the net. I was having a hard time with this algorithm until I saw it explained like this. It helped me finish my project. Perfect!

  • @me-zb7qm
    @me-zb7qm 6 ปีที่แล้ว

    This video is more than 10 years old, yet still so useful. Going into exams with more confidence after watching your explanation, thank you!

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

    Amazing man , really thank you, I have a final exam tomorrow and your video and easy explaining was too helpful for me , Keep on

  • @volrath__
    @volrath__ 9 ปีที่แล้ว +6

    These have been really good for revising for my Data Structures and Algorithms exam today! thank you :)

  • @JoeBuza
    @JoeBuza 11 ปีที่แล้ว +11

    Can you believe this is a 5 year old video? Good work mate

  • @TheRuinedUniverse
    @TheRuinedUniverse 8 ปีที่แล้ว +40

    I like it! I'm going to pay him a visit in the Bath House, in Novigrad, I believe congratulations are in order!

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

      Yes! Finally someone made a Witcher reference. I was browsing xkcd and suddenly "Dijkstra's algorithm" came out of nowhere. I was like "What sorcery is this??"

    • @TheRuinedUniverse
      @TheRuinedUniverse 8 ปีที่แล้ว

      Vojtěch Janků Ahaha 😂😂

  • @RoyalSwish
    @RoyalSwish 14 ปีที่แล้ว

    This algorithm is so annoying, thank you for making it more clear than the textbook.

  • @travolta91
    @travolta91 11 ปีที่แล้ว

    I'' be sitting for Data Structure final exam paper in 3 days time..
    You just saved my life!!~
    :) :)

  • @Masenken
    @Masenken 14 ปีที่แล้ว

    wow, now if math teachers could find ways to be this straightforward and concise in their teaching, we'd all be astrophysicists by now. Nice explanation

  • @ThisaraPinto
    @ThisaraPinto 13 ปีที่แล้ว +1

    You just saved me for my final exam! This is the only problem I had trouble with. Thank you!

  • @c.harris7823
    @c.harris7823 5 ปีที่แล้ว +1

    This is an outstanding video. The only example or scenario that seems to be missing is how to manage/make a decision when you have two (2) edges from the same node (so two different path options from the same node) that cost the same...e.g. going from F to C or from F to D and they both cost 40.

    • @kristijanceple6026
      @kristijanceple6026 5 ปีที่แล้ว

      Note I'm just a student practising this, so I'm not sure if it's correct but seems to have worked and made sense, at least for me so far. But still take it with a massive grain of salt, and if somebody could correct me that'd be great
      choose either one, just make sure it's the shortest one or among the shortest routes as calculating using shortest routes is the whole point of the algorithm. Also if to a certain node you have got 2 paths of the same length, just write something like 60, (A, D) down into the table. For example, if both A and D lead to E at a cost of 60 each, write 60, (A, D) under E. Then you can pick either one, the point is just to cover all the nodes.

  • @gregorygofman1155
    @gregorygofman1155 10 ปีที่แล้ว +3

    Very nice, I think you saved my mark for this semester.
    Cheers from Russia

  • @anasfcb
    @anasfcb 12 ปีที่แล้ว

    Thanks a Lot !! I have Exam tomorrow too !! This algorithm has been a headache to me for a long time untill I saw and understood your very good leçon a few seconds ago ! Thanks again Sir !

  • @max29297
    @max29297 15 ปีที่แล้ว +1

    Now to find other paths, for example, as you said, D to H or H to G, you use the same method that the instructor used in this video. Notice that the instructor started with A - this was his starting vertex. To find a path from a vertex other than A, simply use the same method starting with that vertex instead (for your problems, D or H respectively) Hope all of this helped! :)

  • @towhidskynet
    @towhidskynet 9 ปีที่แล้ว +10

    I love your explanation about algorithm. what is your youtube channel ?. your explanation on BFS and DFS destroyed my 15 year old fear about Graph problems.
    you explain things 1000 better than a Professor of MIT. Thank you !!!

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

      +Mubeen Ali pretty sure he was watching open courseware and was confused by a university presentation that explains theory as well...

    • @ervinzhou8251
      @ervinzhou8251 7 ปีที่แล้ว

      I mean I thought the MIT lecture guy explained it pretty well..

  • @TheSyncan
    @TheSyncan 11 ปีที่แล้ว +1

    B:20, C:40, D:50, E:N/A, F:30, G:70, H:60. For clarity, ignore the "small letters" under the numeric line values; they represet the "via node". Each line value from left to right aligns with each Goal Node's "main column", starting with B (focus on the letters written in blue at the top). That stated, to get the shortest path from A to Goal n: read *only* the numerical values on the final line (#7). (first value is for B .. last value is for H).

  • @lanesetrimmingham3331
    @lanesetrimmingham3331 6 ปีที่แล้ว

    I don't leave comments, but I had to say a job well done with this explanation. Just perfect!!

  • @UnrealLotus
    @UnrealLotus 12 ปีที่แล้ว

    I have an exam tomorrow and you have just saved my life! Thanks!

  • @AndreiPetre
    @AndreiPetre 12 ปีที่แล้ว +1

    to get a best path, take for e.g. the best path from A to D (obtained with Dijkstra's alg), you follow the reverse path given by the parents from which they were explored. So starting from D, you see that it was visited from parent C and has a cost of 50. Now going to C, you see that its parent is F. And F was visited through B (its parent). And finally, B's parent is A. So the path would be A-B-F-C-D. The idea is that you have to reconstruct your path from _goal_ node to the _starting_ node.

  • @excel20
    @excel20 15 ปีที่แล้ว

    You take a look at the values in row 7:
    G can be reached the fastest via D (as D is the last vertex mentioned in column G)
    D is reached via C, C via F, F via B, and B via A.
    So to reach G by the shortest path, you go A->B->F->C->D->G

  • @NoorAhmedAboiye
    @NoorAhmedAboiye 14 ปีที่แล้ว

    Excellent!!! you made it really easy to grasp in 10 minutes than a full class lecture. Thank you very much, keep up the good work.

  • @janashafi6674
    @janashafi6674 8 ปีที่แล้ว

    Soo simple and easy way of exaplaining. Hats OFFF

  • @kamoroso94
    @kamoroso94 8 ปีที่แล้ว

    I'm glad I found this video. I'm working on a project for class that requires this algorithm.

  • @Zerpentile93
    @Zerpentile93 10 ปีที่แล้ว

    Wtf. Didn't know it could be explained so easily. Thanks!

  • @Dimme
    @Dimme 12 ปีที่แล้ว

    What I've concluded is that I need to keep applying Dijkstra's algorithm until my destination node is marked as permanent. Then I can stop and I don't need to visit the rest of the nodes. This makes the algorithm a little more efficient.

  • @ocb2112
    @ocb2112 14 ปีที่แล้ว

    wow i have been searchin through my skripts and through wiki to learn that stuff. but that was the best explanation by far! good job and thank you!

  • @OnlineSGNTheFishBoss
    @OnlineSGNTheFishBoss 6 ปีที่แล้ว

    this video helped me in my final exam.... THANKS A LOT !!!!!!!

  • @wendygal6910
    @wendygal6910 7 ปีที่แล้ว

    You rule! you are the only exapmple like this put there! and Ive been looking for like 2 hours. Thank you :)

  • @graysonwebb2018
    @graysonwebb2018 9 ปีที่แล้ว +1

    Really well explained! And easy to remember. Text books should teach this way of doing it, much more pedagogical.

  • @preritdatta
    @preritdatta 15 ปีที่แล้ว

    God Bless u made it as simple as a childs game!!! Thanks to you,I can now score well.Thanks a lot man!!!!! keep posting!

  • @JohnSmith-hn6kv
    @JohnSmith-hn6kv 7 ปีที่แล้ว

    This is the 3rd algorithm you've taught me!

  • @pratapbhanusolanki6613
    @pratapbhanusolanki6613 9 ปีที่แล้ว

    An awesome explanation with a great example. You have covered all of the possible trickiest cases. Thanks a lot :)

  • @viharsarok
    @viharsarok 13 ปีที่แล้ว +1

    @manojsam79 You only need the last row. Begin at the vertex you're interested in, look up its parent (the node that's written under the optimal cost), than look up the parent's parent etc. Proceed until you reach the starting node. Reverse the list of nodes to get the shortest path.
    E. g. the shortest path to H is
    H, C, F, B, A
    reversed, that is
    A, B, F, C, H

  • @nikkei5410
    @nikkei5410 8 ปีที่แล้ว

    Best Explained I've ever seen.

  • @MrTeetam
    @MrTeetam 11 ปีที่แล้ว

    The TSP is the hardest problem to solve, as it is an equivalent problem to all of the other hardest problems (the rest of those that are NP-complete)--what you are describing is a probabilistic approach which will estimate (but can't guarantee) an optimal path, which one could argue isn't a solution as the problem is to find the optimal path which you may or may not have done with this.

  • @AleksandarGeyne
    @AleksandarGeyne 11 ปีที่แล้ว

    Really helped, man !! I watched this video an hour before my exam, went there and nailed it !!! :D

  • @29leej
    @29leej 8 ปีที่แล้ว

    finally the video for directed weighted Dijkstra graph.

  • @leggermentesara
    @leggermentesara 6 ปีที่แล้ว

    Thanks! 🔝 10 years later 🌱

  • @nawkwan
    @nawkwan 14 ปีที่แล้ว

    Thanks for this clear illustration and explanation. Good Job.

  • @darkcarney1
    @darkcarney1 13 ปีที่แล้ว

    Awesome, Exam later today and was totally blanking on Dijkstra algorithm
    Thanks heaps

  • @cellardoor8943
    @cellardoor8943 8 ปีที่แล้ว

    nice man ! i was trying to understand what " vertex relaxation " was and i got it from your video

  • @colonelbastian6036
    @colonelbastian6036 9 ปีที่แล้ว +6

    Best dijktra demo. evar

  • @smartalex32
    @smartalex32 12 ปีที่แล้ว

    Whichever one you get to first is the one you use. They both are valid paths though, so you can technically use either one.

  • @Cdoddsy
    @Cdoddsy 12 ปีที่แล้ว

    College final in 3 hours and 1/3 of it is going to be on this. I have not shown up to class once and now I am cramming. Pray for me.

  • @h34rtk0rps
    @h34rtk0rps 12 ปีที่แล้ว

    Heh, you're much better than my professors at explaining stuff. Would have thrown a like your way...

  • @mbawaters
    @mbawaters 5 ปีที่แล้ว

    Going from Vertex B to F without processing other neighbors of A is a digression from BFS approach. More often Dijkstra is considered BFS with greedy approach.

  • @annevyner
    @annevyner 11 ปีที่แล้ว

    Thank you soo much i had finals 3 hrs later, i just needed to und this part and im done, Thanks to you u saved hours of mine. Keep it up!

  • @MrTeetam
    @MrTeetam 11 ปีที่แล้ว

    This is a completely different problem to what you describe (TSP). Dijkstra's algorithm finds a 'single source shortest path', and so it computes the shortest path from A to any other vertex. It doesn't require that all (or any) of the other points be included in the solution's path.

  • @PotionDweller
    @PotionDweller 12 ปีที่แล้ว

    Thank you so much, this was fantastic for clarification. Watched two of your videos so far and they've been very well done.

  • @tqbfjotlddltojfbqt
    @tqbfjotlddltojfbqt 12 ปีที่แล้ว

    Very good tutorial, it be even better if you talk about how using a min priority queue is improvement over original algorithm Dijkstra submitted in his paper

  • @AlexWard94
    @AlexWard94 10 ปีที่แล้ว

    Incredibly helpful video - completely ironed out my confusion with this topic! Thank you! :D

  • @muhammadsaad6101
    @muhammadsaad6101 6 ปีที่แล้ว

    Watching this after like 9 years of it. Wow.

  • @MrSyKoM
    @MrSyKoM 13 ปีที่แล้ว

    Thanks, this helped me. I have to specify that this is no the Djikstra original algorithm: this is implemented choosing the min vertex (with a min heap), the original algorithm choses the first node of a queue. Anyway, it does not change the core buisness :) Thanks!

  • @piurek10
    @piurek10 8 ปีที่แล้ว

    good explanation thanks from Poland.

  • @The1311714
    @The1311714 12 ปีที่แล้ว +1

    Thanks so much, It's helping me for my test tomorrow.

  • @rene13cross
    @rene13cross 10 ปีที่แล้ว

    This must be one of the only 16:10 vids on TH-cam :D Thanks for a great explanation btw

  • @amizan8653
    @amizan8653 11 ปีที่แล้ว

    Thanks a lot for posting this, it makes perfect sense now

  • @imorio
    @imorio 14 ปีที่แล้ว

    @elgonost You could choose a random path, or the path given by the algoritm checking for the lowest number. I suspect you could enhance the algoritm to track both paths in that case. Now it only finds the shortest path to a point, if you rewrite the algoritm to track both and continue further steps seperatly, you'd get an algoritm that gives all shortest paths to all points.

  • @Nictron80
    @Nictron80 14 ปีที่แล้ว

    Thanks a lot, this will help me with my test next Tuesday. :)

  • @SPyoutube42069
    @SPyoutube42069 11 ปีที่แล้ว

    a quite nice visual explanation, good stuff

  • @AbyssenTheHoly
    @AbyssenTheHoly 12 ปีที่แล้ว

    Dude. Thank you so much. This helps me a LOT, I have a final tomorrow!

  • @saurabh1qaz2wsx3edc
    @saurabh1qaz2wsx3edc 12 ปีที่แล้ว

    thnk u so mch... have xams in 8 hours :P
    .
    thnx 2 u... will at least score 5 marks for Dijkstra algo :D

  • @CGagnon5
    @CGagnon5 13 ปีที่แล้ว

    I really like this notation. Thank you!

  • @TheSyncan
    @TheSyncan 11 ปีที่แล้ว

    The shortest path, of all in the return set, is A->B=20. But that's not the intent nor the answer for this problem. The algorithm returns a *set* of shortest paths (B-H), given a topology of nodes with multiple connections (or edges). Not just a single, shortest path.

  • @darrylbil
    @darrylbil 7 ปีที่แล้ว

    AWESOME !!!!! U SIR JUST SAVED A LIFE

  • @dheerenr
    @dheerenr 7 ปีที่แล้ว

    Thank you soo much, by far the best explanation ive found :-)

  • @silversvartnad
    @silversvartnad 13 ปีที่แล้ว

    Thi vid makes it very easy to understand the algorithm.
    Thanks a lot =)

  • @4.0.4
    @4.0.4 11 ปีที่แล้ว

    Only gor the sake of a clarification; the "traveling salesman" problem you describe is not the hardest problem to solve. It's just somewhat hard if you want to brute force all paths (which is silly), but even that is not too hard by moderns standards (You can brute-force it in a GPU with CUDA now a days!) You can "solve" it cheaply by using genetic algorithms. Look it up :) Also, it's been thaught for too much time in universities by teachers who don't like to keep up-to-date.

  • @csitbidhyarthi2199
    @csitbidhyarthi2199 12 ปีที่แล้ว

    we can take either of the paths that u might get while executing the algorithm..because u need to find the least cost and u will get equal costs from both least cost paths...we need the method which we will get

  • @zeramino
    @zeramino 12 ปีที่แล้ว

    You can choose the first or the one path you want to choose.

  • @yngwiedmb
    @yngwiedmb 12 ปีที่แล้ว

    you name the nodes to have some reference, it's up to you but usually it is easier to read/understand if you follow a given order such as alphabetic... at least for the starting point as for the final result the logic is shorter path and not names

  • @shrikantbang1692
    @shrikantbang1692 9 ปีที่แล้ว

    Thank You. Easy and Simple explanation.

  • @JudeArasu
    @JudeArasu 14 ปีที่แล้ว

    Hi thanks for this videp.I am student from BITS.This one is too good

  • @marwaneabl7597
    @marwaneabl7597 8 ปีที่แล้ว +6

    Once we are in the final situation (9:01), how can i deduce the shortest path between 2 random vertices ???

    • @altalena9139
      @altalena9139 8 ปีที่แล้ว

      You need to start working on this algorithm with the starting point in mind. In this case, he used A as a starting point. The values at the are the shortest paths from A to any other vertex.

    • @vojtechjanku2534
      @vojtechjanku2534 8 ปีที่แล้ว +2

      Take path from A to G, for example. Start from G: you've written down before that the lowest-cost path approaches G from D. So you now take D and look where the best path leads from. Then it's just recursion all the way back to A, and you just went the best way from A to G (in opposite direction). But I guess you've figured it out after 6 months :-)

  • @rebcabin
    @rebcabin 13 ปีที่แล้ว +1

    Very nice! -- quick question: how did you create the video? Love the hand-written style! Looks like NoteShelf on the iPad.

  • @gigel008
    @gigel008 15 ปีที่แล้ว

    boy you are a real troubleshooter!

  • @arngorf
    @arngorf 11 ปีที่แล้ว

    This is absolutely brilliant. Just what I needed! Thanks!

  • @lizard2728
    @lizard2728 14 ปีที่แล้ว

    Thank you -- awesome explanation! I'm needing to implement the algorithm, and this helps tremendously!

  • @ankitavit
    @ankitavit 11 ปีที่แล้ว

    @RWPCreations Leave the cost and through node as it is...It can also be changed if wanted

  • @EsraaElGhoul
    @EsraaElGhoul 11 ปีที่แล้ว

    WONDERFUL really thanks
    u save a hour from my life

  • @karishmazsweblog5561
    @karishmazsweblog5561 8 ปีที่แล้ว

    u r awesome .. luv ur teaching u r always to da point .. tada

  • @chaitragolkonda2607
    @chaitragolkonda2607 11 ปีที่แล้ว

    awsome I have understood Everything...............
    Very Nice Vedio Thanks..

  • @JvdubN
    @JvdubN 12 ปีที่แล้ว

    There is some agreed upon path to use. You might pick the letter least alphabetical.

  • @elenimoscha8425
    @elenimoscha8425 10 ปีที่แล้ว

    That's been GREAT help! Thanks :))

  • @PuscasuSerghei
    @PuscasuSerghei 11 ปีที่แล้ว

    Finally I understand that. Thanks a lot.

  • @Andrd110
    @Andrd110 14 ปีที่แล้ว

    Excellent, clear n concise

  • @DavidRutten
    @DavidRutten 14 ปีที่แล้ว

    Well done, excellent description. But why no rating?

  • @lilnaable
    @lilnaable 12 ปีที่แล้ว

    A very good videos, I understand really now.
    Thank you

  • @PRASHANTJOSHI1
    @PRASHANTJOSHI1 13 ปีที่แล้ว

    awesome explanation..very clear..hoping for more uploads.. :)

  • @elgonost
    @elgonost 14 ปีที่แล้ว

    In case there are 2 paths with the same minimum cost which node will we choose as next? For example. Lets say there is a path from A to E that costs 20. We have A->B costing 20 and A->E costing 20. Which one will we choose??

  • @pranavtrehun007
    @pranavtrehun007 16 ปีที่แล้ว

    Thanks for the gr8 explanation. it was very helpful.

  • @bmgag19
    @bmgag19 12 ปีที่แล้ว

    what happens when youre picking the smallest path to analyze next (that you havent done yet) and you get two paths of the distance?

  • @KulasangarGowrisangar
    @KulasangarGowrisangar 7 ปีที่แล้ว

    So what's the shortest path here? We get this table done, and how're we suppose to identify the path now? From A to where through which vertices?