Lecture# 11 Shortest Path Problem

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

Lecture# 11

Shortest path problem


Dijkstra Algorithm

By: Dr. Shahzad Ashraf


Overview of Shortest path problem
• Single-Source Shortest Path (SSSP) problem consists of finding the shortest paths between a given vertex v and
all other vertices in the graph.
• Dijkstra's algorithm solves the shortest-path problem for any weighted, directed graph with non-negative
weights.
• It can handle graphs consisting of cycles, but negative weights will cause this algorithm to produce incorrect
results.
• Consequently, it is assumed that
w(e) ≥ 0 for all e ∈ E

• For instance, finding the shortest path from vertex 1 to vertex 13


Overview of Shortest path problem
• After some consideration, we may determine that the shortest path is as
follows, with length 14
Dijkstra's algorithm
• A Dutch computer scientist, Edsger Dijkstra, in 1959, proposed an
algorithm that can be applied to a weighted graph.
• The graph can either be directed or undirected with the condition that the
graph needs to embrace a non-negative value on its every edge.
• Dijkstra's algorithm makes use of weights of the edges for finding the
path that minimizes the total distance (weight) among the source node
and all other nodes.
• This algorithm is also known as the single-source shortest path algorithm.
• It works on the principle of relaxation where an approximation of the
accurate distance is steadily displaced by more suitable values until the
shortest distance is achieved.
• Ultimately, by following the given rules the shortest path between any
two vertices in a graph can be determined through this algorithm.

i. Set all vertices distances = infinity except for the source vertex.
ii. Set the source distance = 0
Dijkstra's algorithm
Dijkstra's algorithm
Working example 1

Relaxation
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Working example 2
Dijkstra's algorithm
Disadvantages

First challenge Second challenge


Dijkstra's algorithm

Try yourself
Dijkstra's algorithm

Crucial acknowledgments
• As with all greedy algorithms, it is essential to make sure that a correct algorithm is
selected (e.g., it always returns the right solution if it is given correct input).
• This algorithm mainly calculates the shortest path to every vertex therefore,
anytime when an optimal path to some other vertex from a determined origin is
required, best to opt it.
Applications
• Traffic Information Systems are most prominent use 
• - Mapping (Map Quest, Google Maps)
• - Routing Systems
Cessation

You might also like