using Dijkstra algorithm to find shortest path in an adjacency matrix

依然范特西╮ 提交于 2019-12-11 02:57:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!