Upload
chamila2345
View
232
Download
0
Embed Size (px)
Citation preview
8/10/2019 1 Varun MSTPresentation
1/42
Definitions
Common Algorithms
Applications
Minimum Spanning TreesAlgorithms and Applications
Varun Ganesan
18.304 Presentation
Varun Ganesan MSTs
http://find/8/10/2019 1 Varun MSTPresentation
2/42
Definitions
Common Algorithms
Applications
Outline
1 Definitions
Graph Terminology
Minimum Spanning Trees
2 Common Algorithms
Kruskals Algorithm
Prims Algorithm
3 Applications
Varun Ganesan MSTs
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
3/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Outline
1 Definitions
Graph Terminology
Minimum Spanning Trees
2 Common Algorithms
Kruskals Algorithm
Prims Algorithm
3 Applications
Varun Ganesan MSTs
http://find/8/10/2019 1 Varun MSTPresentation
4/42
8/10/2019 1 Varun MSTPresentation
5/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Graphs
In graph theory, agraphis an ordered pairG= (V,E)comprising a set of verticesor nodes together with a set
ofedges.
Edgesare 2-element subsets ofVwhich represent aconnection between two vertices.
Edges can either be directed or undirected.Edges can also have aweightattribute.
Varun Ganesan MSTs
D fi i i
http://find/8/10/2019 1 Varun MSTPresentation
6/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Graphs
In graph theory, agraphis an ordered pairG= (V,E)comprising a set of verticesor nodes together with a set
ofedges.
Edgesare 2-element subsets ofVwhich represent aconnection between two vertices.
Edges can either be directed or undirected.Edges can also have aweightattribute.
Varun Ganesan MSTs
D fi iti
http://find/8/10/2019 1 Varun MSTPresentation
7/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Graphs
In graph theory, agraphis an ordered pairG= (V,E)comprising a set of verticesor nodes together with a set
ofedges.
Edgesare 2-element subsets ofVwhich represent aconnection between two vertices.
Edges can either be directed or undirected.Edges can also have aweightattribute.
Varun Ganesan MSTs
Definitions
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
8/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Connectivity
A graph isconnectedwhen there is a path between everypair of vertices.
Acycleis a path that starts and ends with the same
vertex.
Atreeis a connected, acyclic graph.
Varun Ganesan MSTs
Definitions
http://find/8/10/2019 1 Varun MSTPresentation
9/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Connectivity
A graph isconnectedwhen there is a path between everypair of vertices.
Acycleis a path that starts and ends with the same
vertex.
Atreeis a connected, acyclic graph.
Varun Ganesan MSTs
http://find/8/10/2019 1 Varun MSTPresentation
10/42
Definitions
8/10/2019 1 Varun MSTPresentation
11/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Outline
1 Definitions
Graph Terminology
Minimum Spanning Trees
2 Common Algorithms
Kruskals Algorithm
Prims Algorithm
3 Applications
Varun Ganesan MSTs
DefinitionsG h T i l
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
12/42
Definitions
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Spanning Trees
Formally, for a graphG= (V,E), the spanning tree isE Esuch that:
uV : (u, v) E (v,u) E vVIn other words: the subset of edges spans all vertices.
|E|= |V| 1In other words: the number of edges is one less than thenumber of vertices, so that there are no cycles.
Varun Ganesan MSTs
DefinitionsG h T i l
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
13/42
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Spanning Trees
Formally, for a graphG= (V,E), the spanning tree isE Esuch that:
uV : (u, v) E (v,u) E vVIn other words: the subset of edges spans all vertices.
|E|= |V| 1In other words: the number of edges is one less than thenumber of vertices, so that there are no cycles.
Varun Ganesan MSTs
DefinitionsGraph Terminology
http://find/8/10/2019 1 Varun MSTPresentation
14/42
Common Algorithms
Applications
Graph Terminology
Minimum Spanning Trees
Spanning Trees
Formally, for a graphG= (V,E), the spanning tree isE Esuch that:
uV : (u, v) E (v,u) E vVIn other words: the subset of edges spans all vertices.
Linear Graph
|E|= |V| 1In other words: the number of edges is one less than thenumber of vertices, so that there are no cycles.
Varun Ganesan MSTs
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
15/42
DefinitionsKruskals Algorithm
8/10/2019 1 Varun MSTPresentation
16/42
Common Algorithms
Applications
Kruskal s Algorithm
Prims Algorithm
Outline
1 Definitions
Graph Terminology
Minimum Spanning Trees
2 Common Algorithms
Kruskals Algorithm
Prims Algorithm
3 Applications
Varun Ganesan MSTs
Definitions
C Al i hKruskals Algorithm
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
17/42
Common Algorithms
Applications
Kruskal s Algorithm
Prims Algorithm
Main Idea
Start with|V|disjoint components.
Consider lesser weight edges first to incrementally connectcomponents.
Make certain to avoid cycles.
Continue until spanning tree is created.
Varun Ganesan MSTs
http://find/8/10/2019 1 Varun MSTPresentation
18/42
Definitions
Common AlgorithmsKruskals Algorithm
8/10/2019 1 Varun MSTPresentation
19/42
Common Algorithms
Applications
g
Prims Algorithm
Main Idea
Start with|V|disjoint components.
Consider lesser weight edges first to incrementally connectcomponents.
Make certain to avoid cycles.
Continue until spanning tree is created.
Varun Ganesan MSTs
Definitions
Common AlgorithmsKruskals Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
20/42
Common Algorithms
ApplicationsPrims Algorithm
Main Idea
Start with|V|disjoint components.
Consider lesser weight edges first to incrementally connectcomponents.
Make certain to avoid cycles.
Continue until spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
21/42
Common Algorithms
ApplicationsPrims Algorithm
Pseudocode
Kruskals Algorithm
1A= 02foreachvG.V:3MAKE-SET(v)
4foreach(u, v)ordered byweight(u, v), increasing:5 ifFIND-SET(u)=FIND-SET(v):6A= A (u, v)
7UNION(u,
v)8 returnA
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
22/42
Common Algorithms
ApplicationsPrims Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
P i Al i h
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
23/42
Common Algorithms
ApplicationsPrims Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
P i Al ith
http://find/8/10/2019 1 Varun MSTPresentation
24/42
g
ApplicationsPrims Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
25/42
g
ApplicationsPrim s Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
Prims Algorithm
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
26/42
ApplicationsPrim s Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
27/42
ApplicationsPrim s Algorithm
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
A li i
Kruskals Algorithm
Prims Algorithm
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
28/42
ApplicationsPrim s Algorithm
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
A li ti
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
29/42
Applicationss go t
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
30/42
Applicationsg
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
31/42
Applications
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
32/42
Applications
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
33/42
Applications
Proof Of Correctness
Spanning Tree Validity
By avoiding connecting two already connected vertices,output has no cycles.
IfGis connected, output must be connected.Minimality
Consider a lesser total weight spanning tree with at leastone different edgee= (u, v).Ifeleads to less weight, thenewould have been
considered before some edge that connectsuandv in ouroutput.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
34/42
Applications
Outline
1 Definitions
Graph Terminology
Minimum Spanning Trees
2 Common Algorithms
Kruskals Algorithm
Prims Algorithm
3 Applications
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/http://goback/8/10/2019 1 Varun MSTPresentation
35/42
pp
Main Idea
Start withone(any) vertex.
Branch outwards to grow your connected component.
Consider only edges that leave the connected component.
Add smallest considered edge to your connected
component.
Continue until a spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
36/42
pp
Main Idea
Start withone(any) vertex.
Branch outwards to grow your connected component.
Consider only edges that leave the connected component.
Add smallest considered edge to your connected
component.
Continue until a spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
37/42
Main Idea
Start withone(any) vertex.
Branch outwards to grow your connected component.
Consider only edges that leave the connected component.
Add smallest considered edge to your connected
component.
Continue until a spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://goforward/http://find/http://goback/8/10/2019 1 Varun MSTPresentation
38/42
Main Idea
Start withone(any) vertex.
Branch outwards to grow your connected component.
Consider only edges that leave the connected component.
Add smallest considered edge to your connected
component.
Continue until a spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
39/42
Main Idea
Start withone(any) vertex.
Branch outwards to grow your connected component.
Consider only edges that leave the connected component.
Add smallest considered edge to your connected
component.
Continue until a spanning tree is created.
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
40/42
Example
Varun Ganesan MSTs
DefinitionsCommon Algorithms
Applications
Kruskals Algorithm
Prims Algorithm
http://find/8/10/2019 1 Varun MSTPresentation
41/42
Proof of Correctness
Both the spanning tree and minimality argument are nearlyidentical for Prims as they are for Kruskals.
Varun Ganesan MSTs
http://find/8/10/2019 1 Varun MSTPresentation
42/42