SlideShare a Scribd company logo
SHORTEST PATH PROBLEM
Submitted to: Submitted by:
Mrs. Priyanka Soni Krati Katyal
MCA 2nd
Sem
Topic Covered
• GRAPH
• SHORTEST PATH PROBLEM
• DIJKISTRA’S ALGORITHM
• EXAMPLE
• SPANNING TREE
• PRIM’S ALGORITHM
• EXAMPLE
Graph
• A graph is a structure consisting of a set of arrays
(also called dimensions) and a set of edges .
• An edge is a pair of vertices and the two vertices are
called the edge endpoints.
• It is represented as G(V,E).
• Edges(n(n-1)/2)
• Vertices(n)
Types of Graph
• Directed Graph
• Undirected Graph
Cont…
• Connected Graph
• Weighted Graph
• In graph theory, the degree (or valency ) of a vertex of
a graph is the number of edges incident to the vertex,
with loops counted twice.
• The degree of a vertex is denoted or . The maximum
degree of a graph G, denoted by Δ(G), and the minimum
degree of a graph, denoted by δ(G).
• In a regular graph, all degrees are the same, and so we
can speak of the degree of the graph.
Degree
• the number of head endpoints adjacent to a node is
called the indegree of the node and the number of
tail endpoints adjacent to a node is its outdegree.
• The indegree is denoted as deg-(v) and the
outdegree as deg+(v).
Indegree and Outdegree
Shortest Path Problem
• If all the edges in a graph have non-negative weights,
then it is possible to find the shortest path from any
two vertices.
• For example, lets assume in a figure, the shortest
path from B to F is { B, A, C, E, F } with a total cost of
nine.
• Thus, the problem is well defined for a graph that
contains non-negative weights.
• In an weighted graph, the weight of an edge measures
the cost of traveling that edge.
• For example, in a graph representing a network of
airports, the weights could represent: distance, cost or
time.
• Such a graph could be used to answer any of the
following:
– What is the fastest way to get from A to B?
– Which route from A to B is the least expensive?
– What is the shortest possible distance from A to B?
Shortest Path Problem
Dijkistra’s Algorithm
function Dijkstra(Graph, source):
dist[source] ← 0
prev[source] ← undefined
for each vertex v in Graph:
if v ≠ source
dist[v] ← infinity
prev[v] ← undefined
end if
add v to Q
end for
while Q is not empty:
u ← vertex in Q with min dist[u]
remove u from Q
for each neighbor v of u:
alt ← dist[u] + length(u, v)
if alt < dist[v]
dist[v] ← alt
prev[v] ← u
end if
end for
end while
Cont…
return dist[], prev[]
end function
Example:
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
1.Given a road map of Europe find the distance from
Wien to all other capitals on the map. - Represent cities
as vertices, roads as edges and distances between
cities as edge weights. Then, find the shortest paths to
all vertices the vertex that represents Wien.
2. Given the schedule of all airline flights and their
flying-times what is the fastest way to go from Wien to
Calcutta.
3. Urban traffic planning.
4. Routing of telecommunications messages.
Application
Spanning Tree
In the mathematical field of graph theory, a spanning
tree T of an undirected graph G is a sub graph that
includes all the vertices of G that is a tree.
In general, a graph may have several spanning trees,
but a graph that is not connected will not contain a
spanning tree .
Algorithm :
 Prim’s Algorithm
 Kruskal Algorithm
Prim’s Algorithm
Initially discovered in 1930 by Vojtěch Jarník, then
rediscovered in 1957 by Robert C. Prim
Prim's algorithm is a greedy algorithm that finds
a minimum spanning tree for a connected weighted
undirected graph.
This means it finds a subset of the edges that forms
a tree that includes every vertex, where the total weight of
all the edges in the tree is minimized.
A graph can have one or more number of spanning trees.
If the graph has N vertices then the spanning tree will have
n-1 edges
A minimum spanning tree is a spanning tree that has the
minimum weight than all other spanning trees of the
graph.
cont...
Prim’s Algorithm
Step 0: Pick any vertex as a starting vertex. (Call
it A). Mark it with any given color, say orange.
Step 1: Find the nearest neighbor of A (call it B).
Mark both vertex and the edge AB orange.
Step 2: Find the nearest uncolored neighbor to
the orange sub graph (i.e., the closest vertex to
any red vertex). Mark it and the edge connecting
the vertex to the red sub graph in orange.
Step 3: Repeat Step 2 until all vertices are marked
orange. The orange sub graph is a minimum
spanning tree.
Example:
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Reference
•www.google.com
•www.wikipidea.com
•H. coreman
MLSU UNIVERSITY

More Related Content

PPTX
Dijkstra's Algorithm
PPT
1.1 binary tree
PPTX
Bfs and Dfs
PPTX
Binary Tree Traversal
PPTX
Dijkstra’S Algorithm
PPTX
Data structure - Graph
PPT
SINGLE-SOURCE SHORTEST PATHS
Dijkstra's Algorithm
1.1 binary tree
Bfs and Dfs
Binary Tree Traversal
Dijkstra’S Algorithm
Data structure - Graph
SINGLE-SOURCE SHORTEST PATHS

What's hot (20)

PPTX
sum of subset problem using Backtracking
PPTX
Prim's algorithm
PPT
Np cooks theorem
PPTX
Dijkstra's algorithm presentation
PDF
Little o and little omega
PPTX
Trees and graphs
PPTX
Prims and kruskal algorithms
PPTX
Breadth First Search & Depth First Search
PPTX
Asymptotic Notation
PPT
Amortized Analysis of Algorithms
PPT
Regular Grammar
PPT
Backtracking Algorithm.ppt
PPTX
Dijkstra s algorithm
PPT
Randomized algorithms ver 1.0
PDF
Numeric Data types in Python
PPT
Graph algorithm
PPTX
Tree Traversal
PPTX
Red black trees
PPTX
Bellman ford Algorithm
PPT
Binary search tree(bst)
sum of subset problem using Backtracking
Prim's algorithm
Np cooks theorem
Dijkstra's algorithm presentation
Little o and little omega
Trees and graphs
Prims and kruskal algorithms
Breadth First Search & Depth First Search
Asymptotic Notation
Amortized Analysis of Algorithms
Regular Grammar
Backtracking Algorithm.ppt
Dijkstra s algorithm
Randomized algorithms ver 1.0
Numeric Data types in Python
Graph algorithm
Tree Traversal
Red black trees
Bellman ford Algorithm
Binary search tree(bst)
Ad

Viewers also liked (6)

PPT
PPTX
And or graph problem reduction using predicate logic
PPT
Knapsack problem using fixed tuple
And or graph problem reduction using predicate logic
Knapsack problem using fixed tuple
Ad

Similar to Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm) (20)

PPTX
Graph Algorithms
PPTX
UNIT II - Graph Algorithms techniques.pptx
PPTX
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
PDF
Day 5 application of graph ,biconnectivity fdp on ds
PPTX
Data structure and algorithm
PPTX
Ram minimum spanning tree
PDF
Unit-10 Graphs .pdf
PPTX
Spanning Tree in data structure and .pptx
PDF
14 chapter9 graph_algorithmstopologicalsort_shortestpath
PPTX
Graph terminology and algorithm and tree.pptx
PPTX
12_Graph.pptx
PPTX
Unit 4 dsuc
PPTX
Graph theory
PPTX
ppt 1.pptx
PPT
Weighted graphs
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PPTX
Lecture 4- Design Analysis Of ALgorithms
PPTX
logic.pptx
PPTX
Prims Algorithm, Kruskals algorithm, Dijkstra’s Algorithm
PPTX
Graph Algorithms
UNIT II - Graph Algorithms techniques.pptx
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
Day 5 application of graph ,biconnectivity fdp on ds
Data structure and algorithm
Ram minimum spanning tree
Unit-10 Graphs .pdf
Spanning Tree in data structure and .pptx
14 chapter9 graph_algorithmstopologicalsort_shortestpath
Graph terminology and algorithm and tree.pptx
12_Graph.pptx
Unit 4 dsuc
Graph theory
ppt 1.pptx
Weighted graphs
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
Lecture 4- Design Analysis Of ALgorithms
logic.pptx
Prims Algorithm, Kruskals algorithm, Dijkstra’s Algorithm

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Sustainable Sites - Green Building Construction
PDF
Well-logging-methods_new................
DOCX
573137875-Attendance-Management-System-original
PPTX
Geodesy 1.pptx...............................................
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Model Code of Practice - Construction Work - 21102022 .pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
UNIT 4 Total Quality Management .pptx
Construction Project Organization Group 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Sustainable Sites - Green Building Construction
Well-logging-methods_new................
573137875-Attendance-Management-System-original
Geodesy 1.pptx...............................................
additive manufacturing of ss316l using mig welding
CH1 Production IntroductoryConcepts.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Digital Logic Computer Design lecture notes
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx

Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)

  • 1. SHORTEST PATH PROBLEM Submitted to: Submitted by: Mrs. Priyanka Soni Krati Katyal MCA 2nd Sem
  • 2. Topic Covered • GRAPH • SHORTEST PATH PROBLEM • DIJKISTRA’S ALGORITHM • EXAMPLE • SPANNING TREE • PRIM’S ALGORITHM • EXAMPLE
  • 3. Graph • A graph is a structure consisting of a set of arrays (also called dimensions) and a set of edges . • An edge is a pair of vertices and the two vertices are called the edge endpoints. • It is represented as G(V,E). • Edges(n(n-1)/2) • Vertices(n)
  • 4. Types of Graph • Directed Graph • Undirected Graph
  • 6. • In graph theory, the degree (or valency ) of a vertex of a graph is the number of edges incident to the vertex, with loops counted twice. • The degree of a vertex is denoted or . The maximum degree of a graph G, denoted by Δ(G), and the minimum degree of a graph, denoted by δ(G). • In a regular graph, all degrees are the same, and so we can speak of the degree of the graph. Degree
  • 7. • the number of head endpoints adjacent to a node is called the indegree of the node and the number of tail endpoints adjacent to a node is its outdegree. • The indegree is denoted as deg-(v) and the outdegree as deg+(v). Indegree and Outdegree
  • 8. Shortest Path Problem • If all the edges in a graph have non-negative weights, then it is possible to find the shortest path from any two vertices. • For example, lets assume in a figure, the shortest path from B to F is { B, A, C, E, F } with a total cost of nine. • Thus, the problem is well defined for a graph that contains non-negative weights.
  • 9. • In an weighted graph, the weight of an edge measures the cost of traveling that edge. • For example, in a graph representing a network of airports, the weights could represent: distance, cost or time. • Such a graph could be used to answer any of the following: – What is the fastest way to get from A to B? – Which route from A to B is the least expensive? – What is the shortest possible distance from A to B? Shortest Path Problem
  • 10. Dijkistra’s Algorithm function Dijkstra(Graph, source): dist[source] ← 0 prev[source] ← undefined for each vertex v in Graph: if v ≠ source dist[v] ← infinity prev[v] ← undefined end if add v to Q end for
  • 11. while Q is not empty: u ← vertex in Q with min dist[u] remove u from Q for each neighbor v of u: alt ← dist[u] + length(u, v) if alt < dist[v] dist[v] ← alt prev[v] ← u end if end for end while Cont…
  • 24. 1.Given a road map of Europe find the distance from Wien to all other capitals on the map. - Represent cities as vertices, roads as edges and distances between cities as edge weights. Then, find the shortest paths to all vertices the vertex that represents Wien. 2. Given the schedule of all airline flights and their flying-times what is the fastest way to go from Wien to Calcutta. 3. Urban traffic planning. 4. Routing of telecommunications messages. Application
  • 25. Spanning Tree In the mathematical field of graph theory, a spanning tree T of an undirected graph G is a sub graph that includes all the vertices of G that is a tree. In general, a graph may have several spanning trees, but a graph that is not connected will not contain a spanning tree . Algorithm :  Prim’s Algorithm  Kruskal Algorithm
  • 26. Prim’s Algorithm Initially discovered in 1930 by Vojtěch Jarník, then rediscovered in 1957 by Robert C. Prim Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
  • 27. A graph can have one or more number of spanning trees. If the graph has N vertices then the spanning tree will have n-1 edges A minimum spanning tree is a spanning tree that has the minimum weight than all other spanning trees of the graph. cont...
  • 28. Prim’s Algorithm Step 0: Pick any vertex as a starting vertex. (Call it A). Mark it with any given color, say orange. Step 1: Find the nearest neighbor of A (call it B). Mark both vertex and the edge AB orange. Step 2: Find the nearest uncolored neighbor to the orange sub graph (i.e., the closest vertex to any red vertex). Mark it and the edge connecting the vertex to the red sub graph in orange. Step 3: Repeat Step 2 until all vertices are marked orange. The orange sub graph is a minimum spanning tree.