SlideShare ist ein Scribd-Unternehmen logo
1 von 36
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

Weitere ähnliche Inhalte

Was ist angesagt?

Dijkstra algorithm a dynammic programming approach
Dijkstra algorithm   a dynammic programming approachDijkstra algorithm   a dynammic programming approach
Dijkstra algorithm a dynammic programming approachAkash Sethiya
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
Pigeonhole Principle
Pigeonhole PrinciplePigeonhole Principle
Pigeonhole Principlenielsoli
 
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 treeoneous
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnewabhinav108
 
Ford Fulkerson Algorithm
Ford Fulkerson AlgorithmFord Fulkerson Algorithm
Ford Fulkerson AlgorithmMrMoliya
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree Divya Ks
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm sachin varun
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 

Was ist angesagt? (20)

graph theory
graph theory graph theory
graph theory
 
Graph algorithm
Graph algorithmGraph algorithm
Graph algorithm
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Dijkstra algorithm a dynammic programming approach
Dijkstra algorithm   a dynammic programming approachDijkstra algorithm   a dynammic programming approach
Dijkstra algorithm a dynammic programming approach
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Pigeonhole Principle
Pigeonhole PrinciplePigeonhole Principle
Pigeonhole Principle
 
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
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Graph algorithms
Graph algorithmsGraph algorithms
Graph algorithms
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnew
 
Ford Fulkerson Algorithm
Ford Fulkerson AlgorithmFord Fulkerson Algorithm
Ford Fulkerson Algorithm
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
minimum spanning tree
minimum spanning tree minimum spanning tree
minimum spanning tree
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm
 
The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 

Andere mochten auch (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
 

Ähnlich wie 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.pptxasimshahzad8611
 
Hamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's AlgorithmHamilton Path & Dijkstra's Algorithm
Hamilton Path & Dijkstra's AlgorithmMahesh Singh Madai
 
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.pdfzefergaming
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjtepournima055
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slidesHJ DS
 
14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpathSSE_AndyLi
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxsahilpawar2426
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptxARVIND SARDAR
 

Ähnlich wie 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
 

Kürzlich hochgeladen

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 

Kürzlich hochgeladen (20)

Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 

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.