0% found this document useful (0 votes)
35 views20 pages

Dijkstras Algorithm

Dijkstra's algorithm is used to find the shortest paths between nodes in a graph. It can be used for both directed and undirected graphs, as long as all edges have non-negative weights. The algorithm works by maintaining a set of visited nodes and iteratively selecting the unvisited node with the lowest distance. It calculates the distances by considering the weights of neighboring edges. Dijkstra's algorithm has a time complexity of O(V^2) and is commonly used in applications like mapping, routing systems, and traffic information systems.

Uploaded by

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

Dijkstras Algorithm

Dijkstra's algorithm is used to find the shortest paths between nodes in a graph. It can be used for both directed and undirected graphs, as long as all edges have non-negative weights. The algorithm works by maintaining a set of visited nodes and iteratively selecting the unvisited node with the lowest distance. It calculates the distances by considering the weights of neighboring edges. Dijkstra's algorithm has a time complexity of O(V^2) and is commonly used in applications like mapping, routing systems, and traffic information systems.

Uploaded by

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

Dijkstra's algorithm

Group members

 SABA BIBI
(SP15_BCS_019)
 SHAHID AZIZ
(SP15_BCS_031)
Single-Source Shortest Path Problem
 Single-Source Shortest Path Problem - The problem of finding shortest paths from a
source vertex v to all other vertices in the graph.
Dijkstra's algorithm

Dijkstra's algorithm - is a solution to the single-source shortest path problem in


graph theory.

 Both directed and undirected graphs


 All edges must have nonnegative weights
 Graph must be connected
Example

 If the vertices represent the cities and the edge path cost represent the
distance between pair cities then dijkstra’s can be used to find the shortest
route between one city and all others.
Dijkstra's algorithm – Pseudo code
 dist[s] ←0 (distance to source vertex is zero)
for all v ∈ V–{s}
do dist[v] ←∞ (set all other distances to infinity)
S←∅ (S, the set of visited vertices is initially empty)
Q←V (Q, the queue initially contains all vertices)
while Q ≠∅ (while the queue is not empty)
do u ← mindistance(Q,dist) (select the element of Q with the min. distance)
S←S∪{u} (add u to list of visited vertices)
for all v ∈ neighbors[u]
do if dist[v] > dist[u] + w(u, v) (if new shortest path found)
then d[v] ←d[u] + w(u, v) (set new value of shortest path)
 return dist
Example:
Example:


Example:


Example:
Example:


Example:
Example:
Example:


Example:
Example:
Time complexity
Applications of Dijkstra's Algorithm
Traffic Information Systems are most prominent use
- Mapping (Google Maps)
Applications of Dijkstra's Algorithm:

Routing Systems:
Disadvantages
 Main disadvantages:
 The major disadvantage of the algorithm is the fact that it does a blind
search
there by consuming a lot of time waste of necessary resources.
 Another disadvantage is that it cannot handle negative edges. This leads to
acyclic graphs and most often cannot obtain the right shortest path.

You might also like