Dijkstra's Shortest Path Algorithm | Graph Theory

  Рет қаралды 192,645

WilliamFiset

WilliamFiset

Күн бұрын

Explanation of Dijkstra's shortest path algorithm
Dijkstra source code on Algorithms repository:
github.com/williamfiset/algor...
Video slides:
github.com/williamfiset/Algor...
Indexed Priority Queue Video:
• Indexed Priority Queue...
0:00 Intro
0:28 What is Dijkstra's algorithm?
1:13 Algorithm prerequisites
1:55 Video outline
2:28 Dijkstra's algorithm overview
3:50 Lazy Dijkstra's animation
8:10 Lazy Dijkstra's code
11:33 Ignoring stale node optimization
12:11 Finding the shortest path
14:01 Stopping early optimization
15:11 Eager Dijkstra's with an indexed priority queue
16:27 Eager Dijkstra's animation
19:28 Eager Dijkstra's code
20:31 D-ary heap optimization
23:06 The current state of the art for heaps
===================================
Practicing for interviews? I have used, and recommend `Cracking the Coding Interview` which got me a job at Google. Link on Amazon: amzn.to/3cvMof5
A lot of the content on this channel is inspired by the book `Competitive Programming` by Steven Halim which I frequently use as a resource and reference. Link on Amazon: amzn.to/3wC2nix

Пікірлер: 108
@dhrubajyotipaul8204
@dhrubajyotipaul8204 Жыл бұрын
I agree with most people here. This is easily one of the best Dijkstra's Shortest Path Algorithm videos on the internet, if not the best one. I'm so glad that I found you. Thank you making this! ♥
@RyuZebian
@RyuZebian 2 жыл бұрын
Your videos were a HUGE help when I was doing a university course on data structures more than a year ago, and now I'm doing Advent of Code as part of my on-the-job-training. The subreddit kept mentioning "Dijkstra's algorithm" as a way to solve one puzzle. I'd of course heard about it, but hadn't implemented it by myself before. But I immediately though "FISET will surely have covered it as well as he has his other topics..." And sure enough, this video helped me understand both theory and practice. Thank you!
@v0nnyboy
@v0nnyboy 5 жыл бұрын
Thank you for taking the time to make these videos.. They are tremendously useful. Hoping to see more in the future ....
@WilliamFiset-videos
@WilliamFiset-videos 5 жыл бұрын
Glad to hear you enjoy it!
@rish.i
@rish.i 4 жыл бұрын
Outstanding series of videos.ur graph playlist is best on net.Thanks for providing these precious resources for free😃😃😍😍. Hope u ll make series on advanced data structures like fibonacci heaps(for improving djisktra),binomial heap,suffix tree Once again thanks for ur effort.
@abijithbahuleyan785
@abijithbahuleyan785 4 жыл бұрын
This channel is very much UNDERRATED!!
@matveyshishov
@matveyshishov 5 жыл бұрын
Thanks a lot! I love your videos, probably the most professionally done on KZbin!
@vivekpal1004
@vivekpal1004 3 жыл бұрын
Most comprehensive video on Dijkstra. Thank you!
@lukay6230
@lukay6230 5 жыл бұрын
Thank you so much, I implemented it to Unreal Engine 4, for my RTS game. I used 100% of my brain for 3 days to make my own path finder, it worked but it was totaly slow
@80kg
@80kg 2 жыл бұрын
so how did you improve it later? : )
@lukay6230
@lukay6230 2 жыл бұрын
@@80kg I improved it by using this algorythm from video , instead of my own
@enzocecillon1452
@enzocecillon1452 2 жыл бұрын
@@lukay6230 Try A* and nice job :D .
@chanpreetsingh007
@chanpreetsingh007 Жыл бұрын
😉
@Mnkmnkmnk
@Mnkmnkmnk 2 жыл бұрын
For anyone trying to implement this, you can solve leetcode 743 network-delay-time using this.
@mickeynig1
@mickeynig1 3 жыл бұрын
The whole BFS and Dijkstra thing clicked for me. Thank you very much!
@manguy2011
@manguy2011 3 ай бұрын
Amazing man. I thought the MIT videos were good, but YOU ARE THE MAN. You're content has helped me greatly for programming interview concept studying. KEEP IT UP and MUCH LOVE.
@vnpikachu4627
@vnpikachu4627 5 жыл бұрын
Great work very easy to understand
@zrodger2296
@zrodger2296 16 күн бұрын
Not meaning to brag, but: I've stumbled upon an interesting recreational problem, entailing running 700+ dijkstra's algorithms on a graph of over 1mil nodes (whose adjacency matrix occupies 145GB of disk space). This video was of tremendous value to me, and thank you!
@NikitosyaTheGodGamer
@NikitosyaTheGodGamer Жыл бұрын
Thank you for making the video! Much respect!
@jameskennedy674
@jameskennedy674 2 жыл бұрын
Came back here for a little refresher. Great videos!
@WilliamFiset-videos
@WilliamFiset-videos 2 жыл бұрын
I sometimes watch these too when I need a refresher 😂
@mostinho7
@mostinho7 10 ай бұрын
Thanks 1:50 constraint is that graph can’t have negative weight edges It is a greedy algorithm Maintain an array/map mapping each node to the min distance we found for it so far. Initialized to inf 5:30 edge relaxation, a node is marked visited when we relaxed all its edges and update our best distances found 5:50 how priority queue works (with djikstra we use a priority queue for the nodes to visit vs a regular queue in bfs) 12:50 To actually reconstruct the path, keep another array/map of the previous node for each node when you update the shortest path found for it (the updated shortest path is the node we’re going to take) Then you will have a map of Node to Node that maps a node to the previous node in the shortest path 13:00 logic for reconstructing the path from the previous array/map that associated a previous node with each of the nodes Stopped at 13:30
@mateusnascimento1989
@mateusnascimento1989 3 жыл бұрын
Hi, William! Thanks again for the great video. Just wanted to let you know that the link in the description that you said that redirects to the Indexed priority queue video actually redirects to your video on strongly connected components.
@WilliamFiset-videos
@WilliamFiset-videos 3 жыл бұрын
Thanks! Fixed.
@selenawalshsmith7360
@selenawalshsmith7360 4 жыл бұрын
You are an excellent teacher
@namankeshari7332
@namankeshari7332 9 ай бұрын
Thank you so much for this one!
@fangyongsun7182
@fangyongsun7182 3 жыл бұрын
Really good, very practical!!!
@ashminpathak7436
@ashminpathak7436 3 жыл бұрын
This is great. Thank you.
@orangeshoes
@orangeshoes 3 жыл бұрын
Thank you for the video! I wish to ask that the graph you chose at 16:30 to run Dijkstra on has a cycle, doesn't it? between the nodes 1 and 2
@MykolaDolgalov
@MykolaDolgalov 4 жыл бұрын
Wonderful, thank you! :-)
@anuranjankumar2904
@anuranjankumar2904 2 жыл бұрын
First of all, kudos for such an amazing content! I was wondering for the optimisation step at 15:08 can we simply check if the index is visited and continue? (marking visited can be done after this step). Is there any corner case we will miss in this?
@highinstitute2366
@highinstitute2366 4 ай бұрын
you are perfect man...thanks
@chenjason2598
@chenjason2598 Жыл бұрын
Best ever found on the internet!
@Cube2deth
@Cube2deth 3 жыл бұрын
Hiii amazing video, about decrease key, can I use a hashmap + BST so that i can use the hashmap(maps node of BST by index) to delete and then insert the new edge.to and distance into the BST ? That would be much easier to code in an interview compared to IPQ Maybe no need of the BST also, just a multiset() and hashmap to multiset iterators?
@sepehrkhodadadi9403
@sepehrkhodadadi9403 2 жыл бұрын
Huge help ✌🏻😍
@Hajjat
@Hajjat 4 жыл бұрын
Best explanation out there of Dijkstra's. Period.
@briannguyen5057
@briannguyen5057 3 жыл бұрын
very helpful!
@narayanbhat3279
@narayanbhat3279 4 жыл бұрын
Impressive slides! Do you have a code to generate these slides? Or just type them?
@harshranjan8168
@harshranjan8168 9 ай бұрын
can we use ordered_map for this eagers implementation?
@riantix
@riantix 3 жыл бұрын
Hi! I just wanted to point out that at 12:23 you have a cycle in the graph. By the way, these videos is great at explaining these algorithms.
@riantix
@riantix 3 жыл бұрын
Oh I saw that Dijkstra's algorithm works on Directed Acyclic Graphs so I thought that was a requirement. It turns out that the only requirement is edge weights are non-negative.
@anwarulbashirshuaib5673
@anwarulbashirshuaib5673 3 жыл бұрын
15:00 Is it possible to break from the loop as soon as we encounter our destination/target vertex without having to process all its neighbors?
@HarshaVardhan17
@HarshaVardhan17 4 жыл бұрын
In the optimization when there is an end node given at 15:08 , we could have checked if index == e before visiting the edges from the end node, as it is unnecessary as we already got the shortest distance to the end node. Please verify my observation.
@nmamano
@nmamano 3 жыл бұрын
Correct, I was going to point out the same thing.
@gokulkumarbhoomibalan5413
@gokulkumarbhoomibalan5413 2 жыл бұрын
Amazing content! Instead of using a visited array, is it enough we check for the condition dist[index]
@hershjoshi3549
@hershjoshi3549 2 жыл бұрын
yeah that's what I was wondering too. I tried it out and it doesnt seem to add anything and logically it seems redundant
@whatisayoutubehandlebro
@whatisayoutubehandlebro Жыл бұрын
thanks a lot man
@adityavikramsinha408
@adityavikramsinha408 2 жыл бұрын
i love u. This us so effin useful
@puneetkumarsingh1484
@puneetkumarsingh1484 3 жыл бұрын
I would love to see a video on Fibonacci Heap and its applications in Dijkstra's. Please make a video on it.
@shreyashachoudhary480
@shreyashachoudhary480 2 жыл бұрын
Never heard IPQ! Thanks
@techgianttechyforever
@techgianttechyforever 2 жыл бұрын
thanks a lot sir
@chepaiytrath
@chepaiytrath 3 жыл бұрын
In case someone like me is wondering why visited is used in the lazy implementation, the video states at 01:38 that once a node has been visited, its optimal distance cannot be improved. So having a visited set prevents going back to a previously processed node
@sameerpurwar4836
@sameerpurwar4836 2 жыл бұрын
This is because of the priority queue implementation, if u were using, simply queue u would have to check again and again, to ensure that the dist[node] has the minimum value. One could run even without the visited array part, but then it would simply be BFS without any benefits. This is also in sync with the early stopping strategy, later described in the vid. This means that u will only visit a particular node when u have found the minimum distance of that node from the starting node. Quite cool, I would say.
@rahulas721
@rahulas721 2 жыл бұрын
@@sameerpurwar4836 I don't think we actually need a visited array. This is because if an element is visited then we have already found it's shortest path. So instead of maintaining a visited array can just check whether the new distance is less than the one we already have in the dist array. This is something we are already doing, so I think even without the visited array we won't insert the node if it's shortest path has already been found. Is my understanding correct??
@sameerpurwar4836
@sameerpurwar4836 2 жыл бұрын
@@rahulas721 yup, to be honest its cool, and it only becomes clear in hindsight.
@rahulas721
@rahulas721 2 жыл бұрын
@@sameerpurwar4836 Thanks a lot!
@MykolaDolgalov
@MykolaDolgalov 4 жыл бұрын
@WilliamFiset 19:30 it seems like you no longer need the line if dist[index] < minValue: continue because the ipq.decreaseKey will make sure you never have the same index polled twice. Is that correct? Also, I have this question. I do not see the "greedy" part in this implementation. I am wondering whether this implementation will actually work correctly with negative length edges because we actually revisit the already computed lengths and update them, so if we discover a negative length edge, we might update the length correctly. Or am I missing something?
@WilliamFiset-videos
@WilliamFiset-videos 4 жыл бұрын
Yes, I think it should be ok to remove dist[index] < minValue with the ipq since there are no more stale nodes. I would still say that the algorithm is greedy since the next best node is still getting polled for the priority queue.
@MykolaDolgalov
@MykolaDolgalov 4 жыл бұрын
@@WilliamFiset-videos Thank you for your great work! Earlier today, I checked, I added stepCount variable and computed the shortest path with and without that check. The number of steps is the same. Moreover, I was surprised to see that the number of steps equals the number of edges for my dense graph. I have 200 nodes, and 3734 edges, and I do the check exactly 3734 times. I expected that number to be n logm, but it's only m. Are we down to O(m) running time? My current main loop looks like this: while(!pq.isEmpty()) { nodeId = pq.pollMinKeyIndex(); visited[nodeId] = true; curNode = allNodes.get(nodeId); //int curDist = pq.pollMinValue(); //if(dist[nodeId] < curDist) continue; for(List child : curNode) { stepsNum++; int childId = child.get(0); if(visited[childId]) continue; int childDist = child.get(1); int newDist = dist[nodeId] + childDist; if(dist[childId] > newDist) { dist[childId] = newDist; } if(pq.contains(childId)) { pq.decrease(childId, dist[childId]); } else pq.insert(childId, dist[childId]); } } The test data is Tim Roughgarden's file for his Algo course part 1: dijkstraData.txt
@WilliamFiset-videos
@WilliamFiset-videos 4 жыл бұрын
​@@MykolaDolgalov I think that's expected since there are only m edges in the graph. The additional log(n) work comes from the insert and decease operations associated with the PQ, so the time complexity is still on the order of something like ~m*log(n).
@admiringrubin2910
@admiringrubin2910 Ай бұрын
12:10, heap will ensure the tuple with the shortest distance of an index is picked first and then explored. When we come to the stale entry, can't we simply use the visited set to discard it instead of the highlighted check?
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
I am confused about this: when we relax a node v, this means that node v CANNOT have been visited (since we found a smaller distance to it meaning it is not yet popped from the heap which means it is not yet visited). So this means inside the if statement where we relax a node, that node's visited should be false. I tested this in codeforces but it failed This also brings me to a similar question. why do you have if vis[edge.to]: continue ? the if statement for relaxing a node can only be entered if vis[edge.to] is false so there is no need right? but this fails for some reason in codeforces
@okigan
@okigan 2 жыл бұрын
I there a link to javascript/python code as shown in slides (instead of java)?
@himanshudagar8394
@himanshudagar8394 3 жыл бұрын
I don't understand that youtube channels like TechLead have 1M subscribers and this has just a few thousands. People are weird. Anyways superb content :)
@ankurrai7300
@ankurrai7300 10 ай бұрын
I have implemented Fibonacci heap to solve SSSP using Dijkstra's Algorithm in my final semester in college, but yeah theoretically it gives a lower bound, and I haven't tested it's performance against any standard algorithm yet.
@ikaros9727
@ikaros9727 3 жыл бұрын
Hey. I have a question at 14:53. Lets assume we start at node s. We travel to some nodes and realize that we found the "end" of the path we wanted to find. Wouldnt that mean i had to check all nodes for their cost that point to e? I'm confused since as far as i understand the only node tuple i save in the PQ is the ones my prev could visit. But what if my prev didnt have the chance to visit it yet?
@xuanren8208
@xuanren8208 Жыл бұрын
Suppose an unvisited node i has a lower cost to visit e, then we have c_ie + dist_i < dist_e, which means dist_i < dist_e. If this happens, we must choose node i from the PQ instead of e.
@YogeshDorbala
@YogeshDorbala 4 жыл бұрын
@WilliamFiset: For lazy implementation, instead of checking whether if (dist[node.id] < node.value) continue; can't we just check if we had already visited the node and skip it if so?
@HarshaVardhan17
@HarshaVardhan17 4 жыл бұрын
Yes I have the same doubt as well.12:05
@David-uv8kt
@David-uv8kt 3 жыл бұрын
Same thought occurred to me and glad to see I'm not alone.
@bos9824
@bos9824 3 жыл бұрын
you already mark it as visited just before that check. I suppose that would work before you mark it visited
@chepaiytrath
@chepaiytrath 3 жыл бұрын
This would be in line to the fact stated at 01:38 that once a node is visited, its distance cannot be further improved
@hil449
@hil449 Жыл бұрын
12:58 I think you forgot to make clear that when we're implementing we should pass the distance FIRST and then the node index because if we do the way its in the video its gonna fail for this test: 0 -> [{1, 10000}, {2,1}] 1 -> [{2, 10}] 2 -> [{1, 10}] S = 0 So you either need to make a custom comparator for the priority queue or you should use the distance first and the index second: pq.insert((0, s)) instead of pq.insert((s, 0))
@robinandrews5613
@robinandrews5613 2 жыл бұрын
Nice, but the repo link doesn't seem to have the code from the video...
@Nightaxeblade
@Nightaxeblade 4 жыл бұрын
Videos are really helpful, but just a little feedback, I get confused everytime you use 'relax' or 'relaxation'
@noamkoren1839
@noamkoren1839 3 жыл бұрын
It is actually a common thing to say when we improve a path. Thats what you'll see in most books.
@rahulas721
@rahulas721 2 жыл бұрын
@9:15 I don't think we need the visited array. We are using the visited array to make sure that we aren't inserting a node into the priority queue if it's shortest path has already been found. But we can achieve the same functionality without using the visited array. This because if an element is visited then we have already found it's shortest path. ( MinDistance) So instead of maintaining a visited array can just check whether the new distance is less than the one we already have in the dist array. This is something we are already doing, so I think even without the visited array we won't insert the node if it's shortest path has already been found. Is my understanding correct??
@kaze3311
@kaze3311 2 жыл бұрын
I think the visited array is still needed. Because "the new distance is less than the one we already have in the dist array" doesn't mean the new distance is the minimum yet. For example, on a graph represented in this format (from, to, cost): (A, B, 1), (A, C, 8), (B, C, 10), (B, D, 2), (D, C, 3). When B's visited (popped from Q), C's current dist (from A) is 8, while new dist (from B) is 1+10=11. So for C, at this moment "the new distance is less than the one we already have in the dist array", and C will be marked visited. However, the actual min dist of C (from D) is 1+2+3=6, which won't be updated if it's already been marked visited previously.
@rahulas721
@rahulas721 2 жыл бұрын
@@kaze3311 The idea is that everytime we find a path to a node, we check if it's cost is less than the one we already have, if yes then we push it into the Priority Queue. If not then we simply don't push it. If we find a path which is more expensive than the one we already have, we don't mark the node as visited, we simply don't push it in Priority Queue, so if we find the actual shortest path later on it will be considered as it's cost will be less than the value we already have.
@kaze3311
@kaze3311 2 жыл бұрын
@@rahulas721 Yes I think you're right! The purpose of the visited array is simply to avoid adding a (visited) node's edges again and again. But this endless adding can be avoided by comparing the new distance (dist of currently popped node + weight of edge) against the dist array record as you mentioned above, so the visited array is no longer needed. I think my previous comment was mixing the 2 operations: checking visited array vs updating the dist array. Thanks for the explanation!
@kingdominth4
@kingdominth4 5 жыл бұрын
Hi, WilliamFiset. So, after watching the video, I have some concerns with Dijkstra's algorithm. Primarily, is the concern that in some configurations of edge costs, certain nodes may not be reached or, at least, sensibly (Dijkstra's algorithm may yield a nonsensical result) reached with the algorithm. Also, the fact that these graphs use directed edges may complicate the problem further. Dijkstra's algorithm does not look more than one step ahead to find the most optimal path in the current step. It calculates the closest node to it in one instance and advances down the path that includes all the closest path relative to it. But what if, later down the road, it is discovered that the path that Dijkstra's algorithm was advancing down was not the most optimal path after all. This particularly becomes a problem when considering that there are several guards we put in place to prevent backtracking in this implementation (e.g. not visiting previously nodes and utilizing directed edges). If we take the shortest path relative to a node in that instance and later discover that the path we took has a greater cost than another previous one, how do we account for that? We may not even be able to advance from the current node at all if that node doesn't have any outwards edges. Dijkstra's algorithm doesn't really calculate if the path it is traversing will lead to a dead end or if previous nodes can be re-reached. Using the graph at around the 16:26 - 19:27 time mark for reference, at the step where we add node 4 with an edge cost of 13 to the distance array, we go on to later advance to the step where node 4 is updated with a best-distance of 9, since the edge cost from node 3 to node 4 is 2. But what if that edge cost was something outrageous like 100? In this instance, the best distance to 4 and consequently the most optimal path does not lie on the current path. In fact, this shows, at that step that we advanced to node 1 from node 2 instead of to node 4 from node 2, we should have done the opposite. But, as far as I can tell, there is no way to do that with this algorithm. Once you've visited a node you can't 'unvisit' or revisit it. So in one run of Dijkstra's algorithm, following this configuration of edge costs, the algorithm has yielded the wrong result because either the algorithm will still try to complete the path from node 2 to node 4, which is synonymous to jumping from one position in the graph to another non-adjacent position, and doesn't make sense or it will not take the path from node 3 to node 4 because it sees the best distance to that node as 13, and then node 4 will never be visited. Am I correct in my formulation? Is there some workaround for this pitfall besides not using Dijkstra's or does Dijkstra's algorithm require some additional conditions like the edge costs following some logical ordering? Thank you!
@Abietarius
@Abietarius 5 жыл бұрын
A bit late maybe, but at 17:45 you can see that the lowest value to reach node 4 is 13, namely getting there from node 2. That means that if the cost from 3 to 4 would have been outrageous, then you're right and the option of getting to 4 through 2 would have been best and the algorithm would come to that same conclusion when encountering the outrageous value. It's not that it 'unvisits' or revisits a node: it just keeps the then-best path in mind (along with the node on it), and figures out if it can find a better one. In other words, I think the trick to Dijkstra is that it keeps all the current best candidates in an array ("dist" in this case), and only updates a candidate if it finds a better way to get there. Any 'outrageous' value on the current best path would simply cause Dijkstra to devise another best path based on the current optimal values to get to the nodes. Here someone answers what I think is basically the same question by saying "it's not greedy": math.stackexchange.com/questions/352097/dijkstras-algorithm-does-not-work Does any of that help, despite the poor timing? Now that I'm commenting anyway: An infinite amount of thanks to @WilliamFiset for these videos by the way :)
@kingdominth4
@kingdominth4 4 жыл бұрын
Abietarius Thank you. Sorry for my late response too. I think I had Dijkstra’s algorithm confused with a minimum spanning tree algorithm. Dijkstra’s algorithm does not find the optimal continuous path that spans all nodes. It finds the best path to any particular node. That may or may not span multiple nodes. It depends on the edge costs and the orientation of the graph. That’s where I was confused. Dijkstra’s algorithm allows jumps because the optimal path to a particular node may lie on a different path than what we were originally taking. Dijkstra’s only ensures that we process the next most promising edge in the order that they are weighted, which allows us to always construct the optimal path between nodes.
@bos9824
@bos9824 3 жыл бұрын
@@kingdominth4 this is correct!! I was confused with this too since I learned minimum spanning tree first. I hope more people see your comment.
@HoangTran-dm9sf
@HoangTran-dm9sf 4 ай бұрын
I think Advent of code 2023 day 17 puzzle is a perfect example to your concern with maximum 3 consecutive moves as the key constraint to make current optimal path become sub-optimal path later on and we have no way to go back with traditional Dijkstra algorithm. "This particularly becomes a problem when considering that there are several guards we put in place to prevent backtracking in this implementation (e.g. not visiting previously nodes and utilizing directed edges). If we take the shortest path relative to a node in that instance and later discover that the path we took has a greater cost than another previous one, how do we account for that? We may not even be able to advance from the current node at all if that node doesn't have any outwards edges. Dijkstra's algorithm doesn't really calculate if the path it is traversing will lead to a dead end or if previous nodes can be re-reached."
@rajatnagpure7445
@rajatnagpure7445 3 жыл бұрын
I solved dijkstra's without using vector vis(n,false) it works the same... Any comment on that???
@Mnkmnkmnk
@Mnkmnkmnk 2 жыл бұрын
You can visit a node later again, but you will compulsarily have higher distance than what you got earlier so no relaxations happen and it doesn't change your answer. You can reduce that unecessary work by not visiting visited nodes again.
@niksgupta36
@niksgupta36 2 жыл бұрын
I do not understand. How is it different from usual DFS? I guess, Dijkstra's uses BFS to find Shortest path.
@navodyaliyanage473
@navodyaliyanage473 2 жыл бұрын
r u the one in brackhys videos?
@MusavirKhaliq
@MusavirKhaliq 3 жыл бұрын
can i get these slides please
@PwnngNbs
@PwnngNbs 2 жыл бұрын
Basic question, but which language is this? Look like python but not exactly
@liverpoolVS
@liverpoolVS 8 ай бұрын
Man, you are legend! it's my third video on your channel about graphs and everything is super easy to learn. I use you videos to complete Graph course on leetcode because their videos are shit
@thiago75501
@thiago75501 2 жыл бұрын
u should see if vertex is visited before the for statement not inside it
@ahmadsaeed7168
@ahmadsaeed7168 3 жыл бұрын
best
@adhishmalviya2408
@adhishmalviya2408 3 жыл бұрын
Prabhu! Why didn't I find you earlier?
@Dan-tg3gs
@Dan-tg3gs 2 жыл бұрын
do i have to understand d-ary heaps for interviews or is it fine if i just understand the Eager Dijkstra's algorithm?
@codingwithsam4992
@codingwithsam4992 Жыл бұрын
Your video makes me Sleep. Just kidding. Thank you
@vinhdao7582
@vinhdao7582 5 жыл бұрын
It can be better if he label the vertices as a,b,c ...in stead of 1, 2 made confused with the edge weigh .
@WilliamFiset-videos
@WilliamFiset-videos 5 жыл бұрын
Agreed, although thinking about nodes as numbers becomes handy when you start implementing this in code :)
@nam3go3sh3r3
@nam3go3sh3r3 3 жыл бұрын
“built in priority queue” lol said the people making C
@onenation_onebharat
@onenation_onebharat 3 жыл бұрын
3:50
@SakiKnin83
@SakiKnin83 3 жыл бұрын
Why do you need list visited for finding a less cost path? Your algorithm never checks next node with a better path that has been visited...Algorithm ouputs the path with nodes that are visited first. I can't see no greed here :)
@bos9824
@bos9824 3 жыл бұрын
cycle detection
@miguelrodriguez-df8ww
@miguelrodriguez-df8ww 3 жыл бұрын
super confusing.
@palbako1084
@palbako1084 2 жыл бұрын
meg akarok halni
@vishalmishra7018
@vishalmishra7018 4 жыл бұрын
Well you did not talk about correctness at all.
@jakartax1x-rq8kv
@jakartax1x-rq8kv 2 ай бұрын
g, n, s, e Wow these are one of the worst var names ever made.
Dijkstra's Shortest Path Algorithm | Source Code | Graph Theory
9:17
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,2 МЛН
Teenagers Show Kindness by Repairing Grandmother's Old Fence #shorts
00:37
Fabiosa Best Lifehacks
Рет қаралды 35 МЛН
Kitten has a slime in her diaper?! 🙀 #cat #kitten #cute
00:28
ШЕЛБИЛАР | bayGUYS
24:45
bayGUYS
Рет қаралды 590 М.
КАРМАНЧИК 2 СЕЗОН 4 СЕРИЯ
24:05
Inter Production
Рет қаралды 653 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 575 М.
Topological Sort | Kahn's Algorithm | Graph Theory
13:32
WilliamFiset
Рет қаралды 110 М.
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
Breadth First Search Algorithm | Shortest Path | Graph Theory
7:23
WilliamFiset
Рет қаралды 650 М.
The hidden beauty of the A* algorithm
19:22
polylog
Рет қаралды 810 М.
3.6 Dijkstra Algorithm - Single Source Shortest Path - Greedy Method
18:35
Teenagers Show Kindness by Repairing Grandmother's Old Fence #shorts
00:37
Fabiosa Best Lifehacks
Рет қаралды 35 МЛН