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:
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:
Reference
•www.google.com
•www.wikipidea.com
•H. coreman
MLSU UNIVERSITY

More Related Content

What's hot

Greedy algorithm
Greedy algorithmGreedy algorithm
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
ArijitDhali
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
Aliul Kadir Akib
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
Subid Biswas
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
Salman Elahi
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
mansab MIRZA
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
STEFFY D
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
InteX Research Lab
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
Bhavik Vashi
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Nv Thejaswini
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
Shareb Ismaeel
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
oneous
 

What's hot (20)

Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 

Viewers also liked

Modular programming
Modular programmingModular programming
Risc & cisk
Risc & ciskRisc & cisk
Polygon filling
Polygon fillingPolygon filling
And or graph problem reduction using predicate logic
And or graph problem reduction using predicate logicAnd or graph problem reduction using predicate logic
And or graph problem reduction using predicate logic
Mohanlal Sukhadia University (MLSU)
 
Protection
ProtectionProtection
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
Mohanlal Sukhadia University (MLSU)
 

Viewers also liked (6)

Modular programming
Modular programmingModular programming
Modular programming
 
Risc & cisk
Risc & ciskRisc & cisk
Risc & cisk
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
And or graph problem reduction using predicate logic
And or graph problem reduction using predicate logicAnd or graph problem reduction using predicate logic
And or graph problem reduction using predicate logic
 
Protection
ProtectionProtection
Protection
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 

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

Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
asimshahzad8611
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
sakthibalabalamuruga
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
Tribhuvan University
 
Hamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's AlgorithmHamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's Algorithm
Mahesh Singh Madai
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
zefergaming
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
BaliThorat1
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
HJ DS
 
1535 graph algorithms
1535 graph algorithms1535 graph algorithms
1535 graph algorithms
Dr Fereidoun Dejahang
 
14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath
SSE_AndyLi
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
sahilpawar2426
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
ARVIND SARDAR
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
Rashmi Bhat
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
ARVIND SARDAR
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha
 
graph theory
graph theorygraph theory
graph theory
Shashank Singh
 

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

Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Hamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's AlgorithmHamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's Algorithm
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
 
1535 graph algorithms
1535 graph algorithms1535 graph algorithms
1535 graph algorithms
 
14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
graph theory
graph theorygraph theory
graph theory
 

Recently uploaded

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 

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…
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 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.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.