Professional Documents
Culture Documents
DSA 19 - Shortest Path
DSA 19 - Shortest Path
{ arfanskp@gmail.com }
Shortest Path Problem
• The shortest path problem is the problem of finding a path between two
vertices (or nodes) in a graph such that the sum of the weights of its
constituent edges is minimized.
• Shortest path
Shortest path (A, C, E, D, F) between vertices A (6, 4, 5, 1) and (6, 4, 3, 2, 1) are both
and F in the weighted directed graph paths between vertices 6 and 1
Shortest Path Problem cont…
• The most important algorithms for solving this problem are:
1. Dijkstra's algorithm.
2. Bellman–Ford algorithm.
3. A* search algorithm.
4. Floyd–Warshall algorithm.
5. Johnson's algorithm.
6. Viterbi algorithm.
Shortest Path Problem cont…
• The most important algorithms for solving this problem are:
1. Dijkstra's algorithm.
2. Bellman–Ford algorithm.
3. A* search algorithm.
4. Floyd–Warshall algorithm.
5. Johnson's algorithm.
6. Viterbi algorithm.
Shortest Path Problem cont…
Dijkstra's algorithm
• Dijkstra's algorithm is an algorithm for finding the shortest paths
between nodes in a graph, which may represent, for example, road
networks.
• Specifically, the cost to go from Node1 to Node3 is (2), plus the cost
of Node3 to Node4 (5) is 7 (2 + 5).
• A->B->D->F 1+3+3 7
• A->C->E->F 2+2+3 7
• A->B->E->F 1+2+3 6
• A->B->C->D->F 1+1+1+3 6
• A->C->D->F 2+1+3 6
Shortest Path Problem cont…
Dijkstra's algorithm
• So the Shortest paths are:
• A->B->E->F 1+2+3 6
• A->C->D->F 2+1+3 6
• A->B->C->D->F 1+1+1+3 6