Implementing Dijkstra's Algorithm with a Priority Queue

  Рет қаралды 51,842

Mary Elaine Califf

Mary Elaine Califf

Күн бұрын

Пікірлер: 57
@MrJave_
@MrJave_ 10 ай бұрын
Best video on this topic I've found so far. Thank you, professor 👍
@maryelainecaliff
@maryelainecaliff 10 ай бұрын
I'm glad you found it helpful.
@kevinliu5750
@kevinliu5750 2 жыл бұрын
Best Priority Queue tutorial video ever!!! Thanks Marry
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
Thanks! I'm glad you found it helpful.
@ioannispallis7258
@ioannispallis7258 2 жыл бұрын
Thank you very much professor. With such professors you can be only good student.
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
I appreciate the compliment.
@vipulbhardwaj1599
@vipulbhardwaj1599 3 жыл бұрын
really nice visual representation of Dijkstra's, thanks a lot this really helped me with my assignment. :)
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
I'm glad it helped.
@pseudolimao
@pseudolimao 6 ай бұрын
This is it. If you don't understand dijkstra's with heaps, this demystifies it. I just looked at the code implementation and couldn't comprehend it, but this decomposition helped tremendously. The key takeaway is how the priority queue pushes down costly jumps to a node X, so when we get to that item in the queue, that node X will already be "marked" by a shorter path, meaning we can discard that item from the queue, essentially skipping steps. Moreover, since we push "up" the uncostly jumps, our "marks" essentially give us the shortest path to each node, meaning we can stop the algorithm as soon as we have marks equal to the number of nodes. If you imagine a big graph, you're going to "push down" into the queue a bunch of costly items, you're going to "mark" the nodes rather quickly, finding the shortest path as soon as you mark them all, and discarding a considerable amount of items in the process. Notice too, that if you have a huge number of edges, compared to vertices, you're doing a lot of work sorting edges in the queue, that you could spend doing lookups, so intuitively you can start being suspicious that this solution might be equal or worse than the naive approach. I am really pleased with what i unlocked watching this video, thank you Mary. You've also shown me i should, ideally, grab a pen and paper and just go through problems to understand them.
@maryelainecaliff
@maryelainecaliff 6 ай бұрын
I'm glad you found the video helpful. I think you're right that the key to understanding is with the ideas and diagrams, because we don't get bogged down in the specifics of code. Then once we really understand what's going on, it becomes much easier to translate into code (in any language).
@pseudolimao
@pseudolimao 6 ай бұрын
@@maryelainecaliff the code is just that, code for a set of ideas. and some key ideas, especially for these fundamental algorithms' optimized implementations, are very obfuscated within the code. From the array implementation to the priority queue one, the key takeaway is that sorting the queue by edge weight gives us the optimal edge as the first edge we process between those nodes (if one edge is always smaller than two, aka no negative weights), which is almost impossible to decipher this without brute forcing examples in your head/paper or having someone explain it to you, but it's really beautiful once you actually grasp the intention.
@ApoorvaRajBhadani
@ApoorvaRajBhadani 3 жыл бұрын
Thanks for this great explanation! Greetings from India!
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
You are certainly welcome. I'm glad you found it helpful.
@Lod531
@Lod531 3 жыл бұрын
Thanks from ETH Switzerland! The visualization is brilliant.
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Thank you.
@frzhouu2676
@frzhouu2676 2 жыл бұрын
Thanks from China, great explanation!
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
You are welcome!
@ashraf3576
@ashraf3576 3 жыл бұрын
great explanation, really helped for my final exam, greeting from malaysia
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Terima kasih. Glad it helped.
@harishwarreddy2916
@harishwarreddy2916 3 жыл бұрын
If possible try to explain these algorithms along with its pseudo-code.
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Thanks for the suggestion. However, you will find high-level pseudocode for the algorithm in the breadth-first-search video. The algorithm is largely the same, with the primary differences being the use of the priority queue and, of course, the use of the weight of each edge in the cost calculation.
@MissChelsie24
@MissChelsie24 3 жыл бұрын
Best video I've seen on this!
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Thank you.
@SEYMABEYAZTAS-ib4bz
@SEYMABEYAZTAS-ib4bz Жыл бұрын
Is there an animated code of the dijkstra run in java? if they throw
@59sharmanalin
@59sharmanalin 2 жыл бұрын
Great walkthrough! I just want to confirm if (!sptSet[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) dist[v] = dist[u] + graph[u][v]; This condition is already addressed by PQ and should not be used to update distance array every-time we visit neighbours of selected vertex
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
That's correct. We're moving from keeping track of the best cost seen so far in the cost array to putting that into the priority queue to manage for us.
@59sharmanalin
@59sharmanalin 2 жыл бұрын
@@maryelainecaliff Great, thanks!! Keep up the good work, below I just implemented the algo, it's very intuitive and easy algo
@anupritakasbekar8172
@anupritakasbekar8172 2 жыл бұрын
what is the time complexity and space complexity for this
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
That actually depends on the implementation of your graph representation (adjacency list or adjacency matrix) and the implementation of your priority queue. For a discussion of some of the possibilities, you can check out www.baeldung.com/cs/dijkstra-time-complexity.
@shaniduplessis9102
@shaniduplessis9102 Жыл бұрын
Great explanation, thank you!
@maryelainecaliff
@maryelainecaliff Жыл бұрын
Glad it was helpful!
@Tzyt2345
@Tzyt2345 2 жыл бұрын
Thanks a lot for this tutorial. Helped me a lot !
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
Glad to hear that!
@williamson-mcgee7365
@williamson-mcgee7365 3 жыл бұрын
Great tutorial!
@superneutral1663
@superneutral1663 2 жыл бұрын
thankyou very much. was very explained
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
I'm glad you found it helpful.
@varalakshmimamillapalli9964
@varalakshmimamillapalli9964 3 жыл бұрын
Thank you so much ...❤️❤️❤️♥️
@ShivamKendre-fc3su
@ShivamKendre-fc3su 11 ай бұрын
Thank you so much
@maryelainecaliff
@maryelainecaliff 11 ай бұрын
Glad you found it helpful.
@juandiegobermeo5029
@juandiegobermeo5029 3 жыл бұрын
just great, thank you very much!
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Glad you liked it!
@xX_dash_Xx
@xX_dash_Xx 2 жыл бұрын
why did we not include E in the graph, it's gonna feel excluded 😅
@xX_dash_Xx
@xX_dash_Xx 2 жыл бұрын
AND I
@xX_dash_Xx
@xX_dash_Xx 2 жыл бұрын
thank you for saving my ass this semester tho. great vid
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
:-)
@illicitlegacy3783
@illicitlegacy3783 2 жыл бұрын
You are the best!!!
@jerenannagurbanovastudent1082
@jerenannagurbanovastudent1082 Жыл бұрын
the best explanation
@maryelainecaliff
@maryelainecaliff Жыл бұрын
Glad it was helpful!
@nurtasshyntas7745
@nurtasshyntas7745 3 жыл бұрын
Very good! Thanks
@maryelainecaliff
@maryelainecaliff 3 жыл бұрын
Thank you. I'm glad you found it helpful.
@sahnawaz
@sahnawaz 2 жыл бұрын
Amazing!
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
Thank you.
@JordanCagle-k9x
@JordanCagle-k9x 6 ай бұрын
live roger reaction
@SolidCode
@SolidCode 2 жыл бұрын
Great Explanation 😀
@maryelainecaliff
@maryelainecaliff 2 жыл бұрын
Glad it was helpful!
Prim's Algorithm for Finding Minimum Spanning Trees
8:13
Mary Elaine Califf
Рет қаралды 3 М.
3.6 Dijkstra Algorithm - Single Source Shortest Path - Greedy Method
18:35
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 30 МЛН
Priority Queue Introduction
13:18
WilliamFiset
Рет қаралды 473 М.
Dijkstra's Shortest Path Algorithm
11:00
Mary Elaine Califf
Рет қаралды 8 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,4 МЛН
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
Dijkstra algorithm | Code implementation
22:28
Techdose
Рет қаралды 91 М.
The hidden beauty of the A* algorithm
19:22
Polylog
Рет қаралды 901 М.
The Midpoint Circle Algorithm Explained Step by Step
13:33
NoBS Code
Рет қаралды 152 М.