0% found this document useful (0 votes)
73 views

Dijkstra Algorithm

The document summarizes the Dijkstra algorithm. It is a single-source shortest path algorithm that finds the shortest paths from a source node to all other nodes in a graph. The summary describes the steps of running Dijkstra's algorithm on an example graph, including initializing distance values, selecting the unvisited node with the lowest distance, updating distances of neighboring nodes, and repeating until all nodes are visited. Pseudocode and advantages/disadvantages of the algorithm are also provided.

Uploaded by

Sabtain Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Dijkstra Algorithm

The document summarizes the Dijkstra algorithm. It is a single-source shortest path algorithm that finds the shortest paths from a source node to all other nodes in a graph. The summary describes the steps of running Dijkstra's algorithm on an example graph, including initializing distance values, selecting the unvisited node with the lowest distance, updating distances of neighboring nodes, and repeating until all nodes are visited. Pseudocode and advantages/disadvantages of the algorithm are also provided.

Uploaded by

Sabtain Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Presentation

Design and Analysis of Algorithm

Topic:
Dijkstra Algorithm

Group Members:
 Sabtain Ali (FA20-BCS-076)
 Saifullah (FA20-BCS-077)
 Muhammad Zain (FA20-BCS-069)
 Muhammad Kamran (FA20-BCS-056)
 What is Dijkstra Algorithm?
Dijkstra algorithm is a single-source shortest
path algorithm. Single-source means that only one source is given, and
we have to find the shortest path from the source to all the nodes.

 Example:

Step 1:
 The set sptSet is initially empty and distances assigned to vertices
are {0, INF, INF, INF, INF, INF, INF, INF} where INF indicates
infinite.
 Now pick the vertex with a minimum distance value. The vertex 0 is
picked, include it in sptSet. So sptSet becomes {0}. After including
0 to sptSet, update distance values of its adjacent vertices.
 Adjacent vertices of 0 are 1 and 7. The distance values of 1 and 7 are
updated as 4 and 8.
The following subgraph shows vertices and their distance values, only
the vertices with finite distance values are shown. The vertices included
in SPT are shown in green color.
Step 2:
 Pick the vertex with minimum distance value and not already
included in SPT (not in sptSET). The vertex 1 is picked and added to
sptSet.
 So sptSet now becomes {0, 1}. Update the distance values of
adjacent vertices of 1.
 The distance value of vertex 2 becomes 12.

Step 3:
 Pick the vertex with minimum distance value and not already
included in SPT (not in sptSET). Vertex 7 is picked. So sptSet now
becomes {0, 1, 7}.
 Update the distance values of adjacent vertices of 7. The distance
value of vertex 6 and 8 becomes finite (15 and 9 respectively).

Step 4:
 Pick the vertex with minimum distance value and not already
included in SPT (not in sptSET). Vertex 6 is picked. So sptSet now
becomes {0, 1, 7, 6}.
 Update the distance values of adjacent vertices of 6. The distance
value of vertex 5 and 8 are updated.
We repeat the above steps until sptSet includes all vertices of the given
graph. Finally, we get the following Shortest Path Tree (SPT).

 Algorithm:
1. Mark the ending vertex with a distance of zero.
Designate this vertex as current.
2. Find all vertices leading to the current vertex. Calculate
their distances to the end. Since we already know the distance the
current vertex is from the end, this will just require adding the most
recent edge. Don’t record this distance if it is longer than a previously
recorded distance.
3. Mark the current vertex as visited. We will never look at
this vertex again.
4. Mark the vertex with the smallest distance as current,
and repeat from step 2.
 Pseudo Code:
1) Create vertex set Q
2) for each vertex Q in graph
3) dist[v]= ∞
4) Add v to Q
5) dist[source]=O
6) while Q is not empty
7) u=Extract-min[Q]
8) for each neighbor v of u
9) Relax (u,v)

 Advantages:-

1) It is used in Google Maps


2) It is used in finding Shortest Path.
3) It is used in geographical Maps
4) To find locations of Map which refers to vertices of graph.
5) It is used in the telephone network.

 Disadvantages:-

1) It do blind search so wastes lot of time while processing.


2) It cannot handle negative edges.
3) This leads to acyclic graphs and most often cannot obtain the
right shortest path.

You might also like