Minimum Spanning Trees - Massachusetts Institute of...

42
Definitions Common Algorithms Applications Minimum Spanning Trees Algorithms and Applications Varun Ganesan 18.304 Presentation Varun Ganesan MSTs

Transcript of Minimum Spanning Trees - Massachusetts Institute of...

Page 1: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Minimum Spanning TreesAlgorithms and Applications

Varun Ganesan

18.304 Presentation

Varun Ganesan MSTs

Page 2: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

Page 3: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

Page 4: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Graphs

In graph theory, a graph is an ordered pair G = (V ,E)comprising a set of vertices or nodes together with a setof edges.

Edges are 2-element subsets of V which represent aconnection between two vertices.

Edges can either be directed or undirected.Edges can also have a weight attribute.

Varun Ganesan MSTs

Page 5: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Graphs

In graph theory, a graph is an ordered pair G = (V ,E)comprising a set of vertices or nodes together with a setof edges.

Edges are 2-element subsets of V which represent aconnection between two vertices.

Edges can either be directed or undirected.Edges can also have a weight attribute.

Varun Ganesan MSTs

Page 6: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Graphs

In graph theory, a graph is an ordered pair G = (V ,E)comprising a set of vertices or nodes together with a setof edges.

Edges are 2-element subsets of V which represent aconnection between two vertices.

Edges can either be directed or undirected.Edges can also have a weight attribute.

Varun Ganesan MSTs

Page 7: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Graphs

In graph theory, a graph is an ordered pair G = (V ,E)comprising a set of vertices or nodes together with a setof edges.

Edges are 2-element subsets of V which represent aconnection between two vertices.

Edges can either be directed or undirected.Edges can also have a weight attribute.

Varun Ganesan MSTs

Page 8: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Connectivity

A graph is connected when there is a path between everypair of vertices.

A cycle is a path that starts and ends with the samevertex.

A tree is a connected, acyclic graph.

Varun Ganesan MSTs

Page 9: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Connectivity

A graph is connected when there is a path between everypair of vertices.

A cycle is a path that starts and ends with the samevertex.

A tree is a connected, acyclic graph.

Varun Ganesan MSTs

Page 10: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Connectivity

A graph is connected when there is a path between everypair of vertices.

A cycle is a path that starts and ends with the samevertex.

A tree is a connected, acyclic graph.

Varun Ganesan MSTs

Page 11: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

Page 12: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Spanning Trees

Formally, for a graph G = (V ,E), the spanning tree isE ′ ⊆ E such that:

∃u ∈ V : (u, v) ∈ E ′ ∨ (v ,u) ∈ E ′ ∀v ∈ VIn 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

Page 13: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Spanning Trees

Formally, for a graph G = (V ,E), the spanning tree isE ′ ⊆ E such that:

∃u ∈ V : (u, v) ∈ E ′ ∨ (v ,u) ∈ E ′ ∀v ∈ VIn 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

Page 14: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

Spanning Trees

Formally, for a graph G = (V ,E), the spanning tree isE ′ ⊆ E such that:

∃u ∈ V : (u, v) ∈ E ′ ∨ (v ,u) ∈ E ′ ∀v ∈ VIn 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

Page 15: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Graph TerminologyMinimum Spanning Trees

What Makes A Spanning Tree The Minimum?

MST Criterion: When the sum of the edge weights in aspanning tree is the minimum over all spanning trees of a graph

Figure: Suppose (b, f ) is removed and (c, f ) is added...

Varun Ganesan MSTs

Page 16: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

Page 17: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s 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

Page 18: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s 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

Page 19: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s 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

Page 20: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s 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

Page 21: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Pseudocode

Kruskal’s Algorithm1 A = 02 foreach v ∈ G.V :3 MAKE-SET(v)4 foreach (u, v) ordered by weight(u, v), increasing:5 if FIND-SET (u) 6= FIND-SET (v ):6 A = A ∪ (u, v)7 UNION(u, v)8 return A

Varun Ganesan MSTs

Page 22: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 23: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 24: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 25: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 26: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 27: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 28: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 29: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 30: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 31: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 32: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 33: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof Of Correctness

Spanning Tree ValidityBy avoiding connecting two already connected vertices,output has no cycles.If G is connected, output must be connected.

MinimalityConsider a lesser total weight spanning tree with at leastone different edge e = (u, v).If e leads to less weight, then e would have beenconsidered before some edge that connects u and v in ouroutput.

Varun Ganesan MSTs

Page 34: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

Page 35: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Main Idea

Start with one (any) vertex.

Branch outwards to grow your connected component.

Consider only edges that leave the connected component.

Add smallest considered edge to your connectedcomponent.

Continue until a spanning tree is created.

Varun Ganesan MSTs

Page 36: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Main Idea

Start with one (any) vertex.

Branch outwards to grow your connected component.

Consider only edges that leave the connected component.

Add smallest considered edge to your connectedcomponent.

Continue until a spanning tree is created.

Varun Ganesan MSTs

Page 37: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Main Idea

Start with one (any) vertex.

Branch outwards to grow your connected component.

Consider only edges that leave the connected component.

Add smallest considered edge to your connectedcomponent.

Continue until a spanning tree is created.

Varun Ganesan MSTs

Page 38: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Main Idea

Start with one (any) vertex.

Branch outwards to grow your connected component.

Consider only edges that leave the connected component.

Add smallest considered edge to your connectedcomponent.

Continue until a spanning tree is created.

Varun Ganesan MSTs

Page 39: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Main Idea

Start with one (any) vertex.

Branch outwards to grow your connected component.

Consider only edges that leave the connected component.

Add smallest considered edge to your connectedcomponent.

Continue until a spanning tree is created.

Varun Ganesan MSTs

Page 40: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

Page 41: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Proof of Correctness

Both the spanning tree and minimality argument are nearlyidentical for Prim’s as they are for Kruskal’s.

Varun Ganesan MSTs

Page 42: Minimum Spanning Trees - Massachusetts Institute of …math.mit.edu/~rothvoss/18.304.1PM/Presentations/1-Varun-MST... · Definitions Common Algorithms Applications Kruskal’s Algorithm

DefinitionsCommon Algorithms

Applications

Some Applications

Taxonomy

Clustering Analysis

Traveling Salesman Problem Approximation

Varun Ganesan MSTs