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 presentation
PPTX
Dijkstra’S Algorithm
PPT
Spanning trees
PPTX
Shortest path algorithm
PPTX
Graph theory
PPT
Minimum spanning tree
PPTX
Dijkstra s algorithm
PDF
Shortest path algorithms
Dijkstra's algorithm presentation
Dijkstra’S Algorithm
Spanning trees
Shortest path algorithm
Graph theory
Minimum spanning tree
Dijkstra s algorithm
Shortest path algorithms

What's hot (20)

PPTX
Kruskal Algorithm
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
PPTX
Spanning trees & applications
PPTX
Graph data structure and algorithms
PPTX
Shortest path problem
PPTX
Kruskal's algorithm
PDF
Gradient descent method
PPTX
Kruskal’s algorithm
PPTX
Queue ppt
PPT
K mean-clustering algorithm
PPTX
Topological Sorting
PPTX
Graph Theory
PPTX
Dijkstra
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Decision Trees
PPTX
Prims and kruskal algorithms
PPT
Graph theory presentation
PDF
Logistic regression in Machine Learning
PPTX
Dijkstra algorithm a dynammic programming approach
PDF
Bias and variance trade off
Kruskal Algorithm
DESIGN AND ANALYSIS OF ALGORITHMS
Spanning trees & applications
Graph data structure and algorithms
Shortest path problem
Kruskal's algorithm
Gradient descent method
Kruskal’s algorithm
Queue ppt
K mean-clustering algorithm
Topological Sorting
Graph Theory
Dijkstra
SINGLE-SOURCE SHORTEST PATHS
Decision Trees
Prims and kruskal algorithms
Graph theory presentation
Logistic regression in Machine Learning
Dijkstra algorithm a dynammic programming approach
Bias and variance trade off
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 terminology and algorithm and tree.pptx
PPTX
Data structure and algorithm
PPTX
Unit ix graph
PPTX
Hamilton Path & Dijkstra's Algorithm
PPTX
Unit 9 graph
PDF
Shortest path by using suitable algorithm.pdf
PPTX
UNIT II - Graph Algorithms techniques.pptx
PPT
Chap10 slides
PPTX
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
PPT
Unit26 shortest pathalgorithm
PDF
Chap10 slides
PPT
1535 graph algorithms
PDF
Unit-10 Graphs .pdf
PPT
UNIT III discrete mathematice notes availiable
PPTX
Graph Data Structure on social media analysis
PPT
Unit27_MinimumSpanningTree.ppt data structure programming
PDF
14 chapter9 graph_algorithmstopologicalsort_shortestpath
PPT
GraphAlgorithms.pptsfjaaaaaaaaaaaaaaaaaaa
PPTX
Data Structures - Introduction to Graph.pptx
PPT
Dijkstra algorithm ds 57612334t4t44.ppt
Graph terminology and algorithm and tree.pptx
Data structure and algorithm
Unit ix graph
Hamilton Path & Dijkstra's Algorithm
Unit 9 graph
Shortest path by using suitable algorithm.pdf
UNIT II - Graph Algorithms techniques.pptx
Chap10 slides
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit26 shortest pathalgorithm
Chap10 slides
1535 graph algorithms
Unit-10 Graphs .pdf
UNIT III discrete mathematice notes availiable
Graph Data Structure on social media analysis
Unit27_MinimumSpanningTree.ppt data structure programming
14 chapter9 graph_algorithmstopologicalsort_shortestpath
GraphAlgorithms.pptsfjaaaaaaaaaaaaaaaaaaa
Data Structures - Introduction to Graph.pptx
Dijkstra algorithm ds 57612334t4t44.ppt

Recently uploaded (20)

PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Queuing formulas to evaluate throughputs and servers
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
web development for engineering and engineering
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Practice Questions on recent development part 1.pptx
Internet of Things (IOT) - A guide to understanding
Queuing formulas to evaluate throughputs and servers
Road Safety tips for School Kids by a k maurya.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Structs to JSON How Go Powers REST APIs.pdf
Sustainable Sites - Green Building Construction
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Internship_Presentation_Final engineering.pptx
web development for engineering and engineering
Operating System & Kernel Study Guide-1 - converted.pdf
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Arduino robotics embedded978-1-4302-3184-4.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Lecture Notes Electrical Wiring System Components
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Practice Questions on recent development part 1.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.