I am having some trouble wrapping my head around what exactly is the logical flow in which we implement Dijkstra, more precisely what I am having a problem with is how do we actually GET that priority queue, do we build it ( the Priority Queue ) as we go about executing the algorithm on a graph? Or am I looking at this wrong? And then is that it? Do we stop there or do we process this output even further by placing the obtained information in the Priority Queue in some other form or is this is the place where we stop?
I also understand the procedure of producing the corresponding shortest paths which for a chosen node, by recursively following the edges that we took to form the shortest path in the first place, but how is it actually implemented?
In general I'm having a lot of problems actually being able to think up and/or understand suitable implementations of algorithms during my study, I understand the algorithm just fine ( and in some cases I am able to think of a close substitute ) but I just cannot think up clever ways of implementing them, any suggestions?
My best advice is to start with bfs first. If you can implement BFS, you are just one step away from Dijkstra. BFS uses normal queue (first in first out), Dijkstra uses priority queue (element is chosen according to the current distance to source node). That is the only difference.
To answer your specific question:
Again, start with BFS and you will find Dijkstra pretty simple
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.