2

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 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I was typing almost the exact same reply. Including the bold font.
Indeed. You will end up with having a "table" of the cost to travel to every node in your graph, and from which node you came

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.