问题
I have a homework assignment where I'm supposed to find the cheapest airfares between two cities, taking into account layovers.
We are required to use an adjacency matrix along with Dijkstra's algorithm. I'm looking at the algorithm in my book, as well as wikipedia (among other sites). I'm confused because in the parameter for the algorithm it has:
DijkstraAlgorithm(weighted simple digraph, vertex first)
What I'm having a hard time understanding- especially when looking at the entire pseudocode- is why it only takes one vertex as an argument? I need to find the cheapest airfare(shortest path) between two vertices. Why does the algorithm only require one?
回答1:
Dijkstra's will find the shortest path from the provided vertex (first
in your example) to every vertex in your graph. That's why it only takes one vertex as input.
来源:https://stackoverflow.com/questions/8379866/using-dijkstra-algorithm-to-find-shortest-path-in-an-adjacency-matrix