SlideShare a Scribd company logo
Shortest path problem
PRESENTED TO:
MAM MERYAM
DEPARTMENT OF
COMPUTER SCIENCE
GROUP MEMBERS:
IFRA ILYAS (470)
AQSA SHAUKAT (586)
PAZEER ZARA (452)
SAMRA ASLAM (427)
AQSA ANWAR (453)
SHORTEST
PATH
PROBLEM
GRAPH:
 A graph is a representation of a set of objects
where some pairs of objects are connected by links.
 Vertices:
The interconnected objects are represented
by mathematical abstractions called vertices.
 Edges:
The links that connect some pairs of vertices
are called edges.
SHORTEST PATH
PROBLEM :
 The shortest path problem is the problem of finding
a path between two vertices in a graph such that
the sum of the weights of its constituent edges is
minimized.

TYPES OF GRAPH:
1. Weighted graph
2. Un-weighted graph
3. Directed graph
4. Un-directed graph
TYPES OF GRAPHS:
 Weighted:
A graph is a
weighted graph if a
number (weight) is
assigned to each edge.
Example:
Such weights might
represent, for example,
costs, lengths or
capacities, etc.
 Un-weighted:
A graph is a un-
weighted graph if a
number(weight) is not
assigned to each edge.
TYPES OF GRAPHS:
 Directed:
An directed
graph is one in which
edges have orientation.
 Un-directed:
An undirected
graph is one in which
edges have no
orientation.
SHORTEST PATH PROBLEM:
 Given the graph below, suppose we wish to
find the shortest path from vertex 1 to vertex
13.
EXAMPLE:
 After some consideration, we may determine
that the shortest path is as follows, with length
14
 Other paths exists, but they are longer
NEGATIVE CYCLES:
 Clearly, if we have negative vertices, it may be
possible to end up in a cycle whereby each pass
through the cycle decreases the total length
 Thus, a shortest length would be undefined for such
a graph
 Consider the shortest path
from vertex 1 to 4...
 We will only consider non-
negative weights.
SHORTEST PATH EXAMPLE:
 Given:
 Weighted Directed graph G = (V, E).
 Source s, destination t.
 Find shortest directed path from s to t.
s
3
t
2
6
7
4
5
23
18
2
9
14
15
5
30
20
44
16
11
6
19
6
Cost of path s-2-3-5-t
= 9 + 23 + 2 + 16
= 48.
DISCUSSION ITEMS
 How many possible paths are there from s
to t?
 Can we safely ignore cycles? If so, how?
 Any suggestions on how to reduce the set of
possibilities?
s
3
t
2
6
7
4
5
23
18
2
9
14
15
5
30
20
44
16
11
6
19
6
KEY OBSERVATION:
 A key observation is that if the shortest path contains
the node v, then:
 It will only contain v once, as any cycles will only add to the
length.
 The path from s to v must be the shortest path to v from s.
 The path from v to t must be the shortest path to t from v.
DIJKSTRA’S ALGORITHM:
 Works when all of the weights are positive.
 Provides the shortest paths from a source to
all other vertices in the graph.
 Can be terminated early once the shortest
path to t is found if desired.
EXAMPLE:
 Consider the graph:
 the distances are appropriately initialized
 all vertices are marked as being unvisited
EXAMPLE:
 Visit vertex 1 and update its neighbours,
marking it as visited
 the shortest paths to 2, 4, and 5 are
updated
EXAMPLE:
 The next vertex we visit is vertex 4
 vertex 5 1 + 11 ≥ 8 don’t update
 vertex 7 1 + 9 < ∞ update
 vertex 8 1 + 8 < ∞ update
EXAMPLE:
 Next, visit vertex 2
 vertex 3 4 + 1 < ∞ update
 vertex 4 already
visited
 vertex 5 4 + 6 ≥ 8 don’t update
 vertex 6 4 + 1 < ∞ update
EXAMPLE:
 Next, we have a choice of either 3 or 6
 We will choose to visit 3
 vertex 5 5 + 2 < 8 update
 vertex 6 5 + 5 ≥ 5 don’t update
EXAMPLE:
 We then visit 6
 vertex 8 5 + 7 ≥ 9 don’t update
 vertex 9 5 + 8 < ∞ update
EXAMPLE:
 Next, we finally visit vertex 5:
 vertices 4 and 6 have already been visited
 vertex 7 7 + 1 < 10 update
 vertex 8 7 + 1 < 9 update
 vertex 9 7 + 8 ≥ 13 don’t update
EXAMPLE:
 Given a choice between vertices 7 and 8, we
choose vertex 7
 vertices 5 has already been visited
 vertex 8 8 + 2 ≥ 8 don’t update
EXAMPLE:
 Next, we visit vertex 8:
 vertex 9 8 + 3 < 13 update
EXAMPLE:
 Finally, we visit the end vertex
 Therefore, the shortest path from 1 to 9 has length
11
EXAMPLE:
 We can find the shortest path by working back from
the final vertex:
 9, 8, 5, 3, 2, 1
 Thus, the shortest path is (1, 2, 3, 5, 8, 9)
Shortest path problem

More Related Content

PPTX
Dijkstra’s algorithm
PPT
Applications of graphs
PPTX
Dijkstra's algorithm
PPTX
Dijkstra's Algorithm
PPTX
Shortest path algorithm
PPTX
Dijkstra & flooding ppt(Routing algorithm)
PPTX
Dynamic Programming
PPTX
Distance Vector Routing Protocols
Dijkstra’s algorithm
Applications of graphs
Dijkstra's algorithm
Dijkstra's Algorithm
Shortest path algorithm
Dijkstra & flooding ppt(Routing algorithm)
Dynamic Programming
Distance Vector Routing Protocols

What's hot (20)

PPT
Minimum spanning tree
PPT
Trees
PDF
Shortest Path in Graph
PPT
Graphs - Discrete Math
PPTX
DAA-Floyd Warshall Algorithm.pptx
PPT
Propositional Logic and Pridicate logic
PPTX
Data structure - Graph
PPT
Spanning trees
PPTX
Topological Sorting
PPT
1.1 binary tree
PPTX
CMSC 56 | Lecture 8: Growth of Functions
PPT
Binary Search
PPTX
Knapsack Problem
PPTX
Binary Tree in Data Structure
PPTX
Breadth First Search & Depth First Search
PPTX
Depth first search [dfs]
PPTX
Shortest path algorithm
PPTX
Connectivity of graphs
PPTX
Red black trees
Minimum spanning tree
Trees
Shortest Path in Graph
Graphs - Discrete Math
DAA-Floyd Warshall Algorithm.pptx
Propositional Logic and Pridicate logic
Data structure - Graph
Spanning trees
Topological Sorting
1.1 binary tree
CMSC 56 | Lecture 8: Growth of Functions
Binary Search
Knapsack Problem
Binary Tree in Data Structure
Breadth First Search & Depth First Search
Depth first search [dfs]
Shortest path algorithm
Connectivity of graphs
Red black trees
Ad

Viewers also liked (20)

PPTX
Dijkstra’S Algorithm
PDF
All pairs shortest path algorithm
PDF
Conservation of codon optimality
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
PDF
Dijkstra's Algorithm
PDF
Shortest Path Problem
PPTX
Dijkstra
DOCX
Dijkstra algorithm
PPTX
My presentation all shortestpath
PDF
Shortest Path Search in Real Road Networks with pgRouting
PDF
Shortest path search for real road networks and dynamic costs with pgRouting
PDF
21 All Pairs Shortest Path
PPT
Biconnected components (13024116056)
PPTX
Dijkstra's Algorithm
PPT
Unit26 shortest pathalgorithm
PPT
Avl trees
PPTX
AVL Tree
PDF
Solving The Shortest Path Tour Problem
PPTX
Floyd Warshall algorithm easy way to compute - Malinga
PPTX
The Shortest Route Problem
Dijkstra’S Algorithm
All pairs shortest path algorithm
Conservation of codon optimality
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Dijkstra's Algorithm
Shortest Path Problem
Dijkstra
Dijkstra algorithm
My presentation all shortestpath
Shortest Path Search in Real Road Networks with pgRouting
Shortest path search for real road networks and dynamic costs with pgRouting
21 All Pairs Shortest Path
Biconnected components (13024116056)
Dijkstra's Algorithm
Unit26 shortest pathalgorithm
Avl trees
AVL Tree
Solving The Shortest Path Tour Problem
Floyd Warshall algorithm easy way to compute - Malinga
The Shortest Route Problem
Ad

Similar to Shortest path problem (20)

PPT
Shortest path
PDF
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
PPTX
dms slide discrete mathematics sem 2 engineering
PPTX
Shortest-Path Problems - Graph Theory in Computer Applications
PPT
bellman-ford Theorem.ppt
PDF
14 chapter9 graph_algorithmstopologicalsort_shortestpath
PPTX
Single source shortestpath
PPTX
Dijkstra's Shortest Path Algorithm Working
PPTX
Data structure and algorithm
PPT
2.6 all pairsshortestpath
PPTX
Dijkstra's algorithm presentation
PPTX
PDF
Dijkstra Shortest Path Visualization
PDF
Daa chpater14
PPT
9_graphs2.v4.ppt
PPTX
15-bellmanFord.pptx...........................................
PPTX
routing algorithm
PPTX
12_Graph.pptx
PPTX
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
Shortest path
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
Lecture 16 - Dijkstra's Algorithm.pdf
dms slide discrete mathematics sem 2 engineering
Shortest-Path Problems - Graph Theory in Computer Applications
bellman-ford Theorem.ppt
14 chapter9 graph_algorithmstopologicalsort_shortestpath
Single source shortestpath
Dijkstra's Shortest Path Algorithm Working
Data structure and algorithm
2.6 all pairsshortestpath
Dijkstra's algorithm presentation
Dijkstra Shortest Path Visualization
Daa chpater14
9_graphs2.v4.ppt
15-bellmanFord.pptx...........................................
routing algorithm
12_Graph.pptx
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
web development for engineering and engineering
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Project quality management in manufacturing
PDF
composite construction of structures.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Sustainable Sites - Green Building Construction
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Construction Project Organization Group 2.pptx
573137875-Attendance-Management-System-original
Foundation to blockchain - A guide to Blockchain Tech
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
web development for engineering and engineering
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Operating System & Kernel Study Guide-1 - converted.pdf
Lecture Notes Electrical Wiring System Components
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Project quality management in manufacturing
composite construction of structures.pdf
OOP with Java - Java Introduction (Basics)
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Sustainable Sites - Green Building Construction
Mitigating Risks through Effective Management for Enhancing Organizational Pe...

Shortest path problem

  • 3. GROUP MEMBERS: IFRA ILYAS (470) AQSA SHAUKAT (586) PAZEER ZARA (452) SAMRA ASLAM (427) AQSA ANWAR (453)
  • 5. GRAPH:  A graph is a representation of a set of objects where some pairs of objects are connected by links.  Vertices: The interconnected objects are represented by mathematical abstractions called vertices.  Edges: The links that connect some pairs of vertices are called edges.
  • 6. SHORTEST PATH PROBLEM :  The shortest path problem is the problem of finding a path between two vertices in a graph such that the sum of the weights of its constituent edges is minimized. 
  • 7. TYPES OF GRAPH: 1. Weighted graph 2. Un-weighted graph 3. Directed graph 4. Un-directed graph
  • 8. TYPES OF GRAPHS:  Weighted: A graph is a weighted graph if a number (weight) is assigned to each edge. Example: Such weights might represent, for example, costs, lengths or capacities, etc.  Un-weighted: A graph is a un- weighted graph if a number(weight) is not assigned to each edge.
  • 9. TYPES OF GRAPHS:  Directed: An directed graph is one in which edges have orientation.  Un-directed: An undirected graph is one in which edges have no orientation.
  • 10. SHORTEST PATH PROBLEM:  Given the graph below, suppose we wish to find the shortest path from vertex 1 to vertex 13.
  • 11. EXAMPLE:  After some consideration, we may determine that the shortest path is as follows, with length 14  Other paths exists, but they are longer
  • 12. NEGATIVE CYCLES:  Clearly, if we have negative vertices, it may be possible to end up in a cycle whereby each pass through the cycle decreases the total length  Thus, a shortest length would be undefined for such a graph  Consider the shortest path from vertex 1 to 4...  We will only consider non- negative weights.
  • 13. SHORTEST PATH EXAMPLE:  Given:  Weighted Directed graph G = (V, E).  Source s, destination t.  Find shortest directed path from s to t. s 3 t 2 6 7 4 5 23 18 2 9 14 15 5 30 20 44 16 11 6 19 6 Cost of path s-2-3-5-t = 9 + 23 + 2 + 16 = 48.
  • 14. DISCUSSION ITEMS  How many possible paths are there from s to t?  Can we safely ignore cycles? If so, how?  Any suggestions on how to reduce the set of possibilities? s 3 t 2 6 7 4 5 23 18 2 9 14 15 5 30 20 44 16 11 6 19 6
  • 15. KEY OBSERVATION:  A key observation is that if the shortest path contains the node v, then:  It will only contain v once, as any cycles will only add to the length.  The path from s to v must be the shortest path to v from s.  The path from v to t must be the shortest path to t from v.
  • 16. DIJKSTRA’S ALGORITHM:  Works when all of the weights are positive.  Provides the shortest paths from a source to all other vertices in the graph.  Can be terminated early once the shortest path to t is found if desired.
  • 17. EXAMPLE:  Consider the graph:  the distances are appropriately initialized  all vertices are marked as being unvisited
  • 18. EXAMPLE:  Visit vertex 1 and update its neighbours, marking it as visited  the shortest paths to 2, 4, and 5 are updated
  • 19. EXAMPLE:  The next vertex we visit is vertex 4  vertex 5 1 + 11 ≥ 8 don’t update  vertex 7 1 + 9 < ∞ update  vertex 8 1 + 8 < ∞ update
  • 20. EXAMPLE:  Next, visit vertex 2  vertex 3 4 + 1 < ∞ update  vertex 4 already visited  vertex 5 4 + 6 ≥ 8 don’t update  vertex 6 4 + 1 < ∞ update
  • 21. EXAMPLE:  Next, we have a choice of either 3 or 6  We will choose to visit 3  vertex 5 5 + 2 < 8 update  vertex 6 5 + 5 ≥ 5 don’t update
  • 22. EXAMPLE:  We then visit 6  vertex 8 5 + 7 ≥ 9 don’t update  vertex 9 5 + 8 < ∞ update
  • 23. EXAMPLE:  Next, we finally visit vertex 5:  vertices 4 and 6 have already been visited  vertex 7 7 + 1 < 10 update  vertex 8 7 + 1 < 9 update  vertex 9 7 + 8 ≥ 13 don’t update
  • 24. EXAMPLE:  Given a choice between vertices 7 and 8, we choose vertex 7  vertices 5 has already been visited  vertex 8 8 + 2 ≥ 8 don’t update
  • 25. EXAMPLE:  Next, we visit vertex 8:  vertex 9 8 + 3 < 13 update
  • 26. EXAMPLE:  Finally, we visit the end vertex  Therefore, the shortest path from 1 to 9 has length 11
  • 27. EXAMPLE:  We can find the shortest path by working back from the final vertex:  9, 8, 5, 3, 2, 1  Thus, the shortest path is (1, 2, 3, 5, 8, 9)