0% found this document useful (0 votes)
23 views12 pages

DSA 19 - Shortest Path

Uploaded by

littlegirl127138
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views12 pages

DSA 19 - Shortest Path

Uploaded by

littlegirl127138
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Data Structures and Algorithms Arfan Shahzad

{ [email protected] }
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

• The problem of finding the shortest path between two intersections


(nodes) on a road map may be modeled as a special case of the shortest
path problem in graphs.
Shortest Path Problem cont…

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.

• It was perceived by computer scientist Edsger W. Dijkstra in 1956 and


published three years later.
Shortest Path Problem cont…
Dijkstra's algorithm
• Blue circles are nodes/ vertices.

• Black lines are edges/ paths/ links.

• The numbers on the node paths represent


the "cost" of going between nodes.

• Our problem is to find most cost


efficient route from Node1 to 4.
Shortest Path Problem cont…
Dijkstra's algorithm
• The shortest path from Node1 to Node4 is to take Node1 to Node3 to
Node4, as that is the path where the least cost is incurred.

• Specifically, the cost to go from Node1 to Node3 is (2), plus the cost
of Node3 to Node4 (5) is 7 (2 + 5).

• Now, we can see that the alternative (Node1 to Node2 to Node4) is


much more costly (it costs 11, versus our 7).
Shortest Path Problem cont…
Dijkstra's algorithm
• Find the Shortest Paths of following graph using Dijkstra’s Algorithm?
Shortest Path Problem cont…
Dijkstra's algorithm
• Possible shortest paths from node A to F are give below:

• 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

You might also like