You are on page 1of 33

2021-2022 Academic Year

University of Computer Studies (Sittwe)


Final Year Project Presentation for Analysis of Algorithms

A Shortest Path Algorithm


Present By
Group-VIIII

Supervised By
Daw Nann Seint Seint Soe
Lecture
Group member

 Ma Mya Khin Cho Tun (5CS-16)


 Ma Ni Ni Win (5CS-30)
 Ma Kay Khine Mon (5CS-40)
 Mg Min Myat (5CS-45)
Outline
 Introduction
 Project Explanation
 Objective
 Algorithm
 Problem
 Java code
 Conclusion
Project Explanation
 What is Shortest path algorithm?
The shortest path problem can be defined for graphs whether
undirected, directed, or mixed. It is defined here for undirected graphs;
for directed graphs the definition of path requires that consecutive
vertices be connected by an appropriate directed edge.
Objective
To study, determine and identify the shortest path in a network.
To use some of its applications are For map application and For
telephone networks (such as Facebook, Twitter, Instagram, Google
Map and IP routing etc.).
Before learning any algorithm, we should know the fundamental
purpose of using an algorithm that could help us in real-world
applications. Such as, for Dijkstra’s algorithm, we are trying to find
the solutions to least path based problems. 
Shortest Path Algorithm Explanation
1. Graph
Shortest Path Algorithm Explanation
2. Adjacency Matrix
a b c d e
a _ 7 5 _ _
b _ _ _ 3 _
c _ 3 _ 8 2
d _ _ _ _ 4
e 10 _ _ _ _
Shortest Path Algorithm Explanation
3. Adjacency List
Shortest Path Algorithm Explanation
4. Formula

If (d(u) + c(u,v) < d(v))


{
d(v) = d(u) + c(u,v);
}
Shortest Path Algorithm Explanation
• Initialize

a b c d e
Cost 0 inf inf inf Inf
Visited 0 0 0 0 0
Parent
Node
Shortest Path Algorithm Explanation
• Step – 1

Pointer -a a b c d e
Cost 0 7 5 inf Inf
Visited 1 0 0 0 0
Parent _ a a
Node
Cost If (0 + 7 < inf) {b = 7;}  true
Updated If (0 + 5 < inf) {c = 5;}  true
Next min(b,c) = min(7,5) = c
Pointer
Shortest Path Algorithm Explanation
• Step-2

Pointer - c a b c d e
Cost 0 7 5 13 7
Visited 1 0 1 0 0
Parent _ a a c c
Node
Cost If(5 + 3 < 7) {b = 7;}  false
Updated If(5 + 8 < inf ) {d = 13;}  true
If(5 + 2 < inf ) {e = 7;}  true
Next min (b,d,e) = min(7,13,7) = b
Pointer
Shortest Path Algorithm Explanation
• Step-3

Pointer - c a b c d e
Cost 0 7 5 10 7
Visited 1 1 1 0 0
Parent _ a a b c
Node
Cost If(7 + 3 < 13) {d = 10;}  true
Updated
Next min (d) = min(10) = d
Pointer
Shortest Path Algorithm Explanation
• Step-4

Pointer - d a b c d e
Cost 0 7 5 10 7
Visited 1 1 1 1 0
Parent _ a a b c
Node
Cost If(10 + 4 < 7) {e = 7;}  false
Updated
Next min (e) = min(7) = e
Pointer
Shortest Path Algorithm Explanation
• Step-5

Pointer - d a b c d e
Cost 0 7 5 10 7
Visited 1 1 1 1 1
Parent _ a a b c
Node
Cost If(7 + 10 < 0) {a = 0;}  false
Updated
Next Null, all nodes are visited.
Pointer
Shortest Path Algorithm Explanation
• Path finding(a to other)

Pointer - a b c d e
d
Cost 0 7 5 10 7
Visited 1 1 1 1 1
Parent _ a a b c
Node
Shortest Path Algorithm Explanation
• Path finding (a to other)

 ‘a’ to ‘b’ = a  b
 ‘a’ to ‘c’ = a  c
 ‘a’ to ‘d’ = a  b  d
 ‘a’ to ‘e’ = a  c  e
Shortest Path Algorithm
• Once the algorithm is over, we use backtrack from the destination
vertex to the source vertex to find the path.
• A minimum priority queue can be used to efficiently receive the vertex
with the least path distance.
Shortest Path Algorithm
•Function shortestPath(G,S) unction Dijkstra(Graph, source):
•2: for each vertex v in Graph: // Initialization
•3: dist[v] := infinity// initial distance from source to vertex v is set to infinite
•4: previous[v] := undefined // Previous node in optimal path from source
•5: dist[source] := 0 // Distance from source to source
•6: Q := the set of all nodes in Graph // all nodes in the graph are unoptimized - thus are in Q
•7: while Q is not empty: // main loop
•8: u := node in Q with smallest dist[ ]
for each vertex V in G
distance[V] <- infinite
previous[V] <- Null
if V != S, add V to Priority Queue Q
distance[S] <- 0
while Q IS NOT EMPTY
U <- Extract MIN from Q
Shortest Path Algorithm
9: remove u from Q
10:for each neighbor v of u:// where v has not yet been removed from Q.
11:alt := dist[u] + dist_between(u, v)
12:if alt < dist[v] // Relax (u,v)
13:dist[v] := alt
14:previous[v] := u
15:return previous[ ]
Shortest Path Algorithm
• Let distance of start vertex from vertex = 0
• Let distance of all vertices from start = ∞ (infinity)
Repeat
Visit the unvisited vertex with the smallest known distance from the
start vertex
For the current vertex, examine its unvisited neighbors
For the current vertex, calculate distance of each neighbors from
start vertex
If the calculate distance of this vertex is less than the known distance,
update the shortest distance
Shortest Path Algorithm
Update the previous vertex for each of the updated distances
Add the current vertex for each of the updated distances
Until all vertices visited
Shortest Path Algorithm
• Let distance of start vertex from vertex = 0
• Let distance of all vertices from start = ∞ (infinity)
WHILE vertices remain unvisited
Visit the unvisited vertex with the smallest known distance from the
start vertex(call this ‘current vertex’)
FOR each unvisited neighbor of the current vertex
Calculate the distance from start vertex
If the calculate distance of this vertex is less than the known distance
Shortest Path Algorithm
• Update shortest distance to this vertex
Update the previous vertex with the current vertex
end if
NEXT unvisited neighbor
Add the current vertex to the list of visited vertices
END WHILE
Problem

4 A
B 1
c
7
6
2

D
E
Java Code
Java Code
Java Code
Program output
Result of output
• Distance from source to Destination is
• 0------->0
• 1------->4
• 2------->5
• 3------->6
• 4------->7
Conclusion
• Among many, we have discussed the Dijkstra(a shortest path)
algorithm used for finding the shortest path, however, one of the
obstacles while implementing the algorithm on the internet is to
provide a full representation of the graph to execute the algorithm as
an individual router has a complete outline for all the routers on the
internet.
References
Shortest Path Algorithm Explanation from
MIG-Myanmar Innovative Group: http://programmingknowledge.blogspot.com/

 Shortest Path Algorithm from


Gitta.Info: http://www.gitta.info/Accessibiliti/en/html/Dijkstra_learningObject1.html
 Problem and Java Code from
DeAn Careers: http://www.youtube.com/channel/UCp9ysiThJIq2ga9Rz-RLePw

You might also like