Minimum Spanning Trees - Massachusetts Institute of...

Preview:

Citation preview

DefinitionsCommon Algorithms

Applications

Minimum Spanning TreesAlgorithms and Applications

Varun Ganesan

18.304 Presentation

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Outline

1 DefinitionsGraph TerminologyMinimum Spanning Trees

2 Common AlgorithmsKruskal’s AlgorithmPrim’s Algorithm

3 Applications

Varun Ganesan MSTs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

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

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

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

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

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

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

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

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

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

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

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

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

DefinitionsCommon Algorithms

Applications

Kruskal’s AlgorithmPrim’s Algorithm

Example

Varun Ganesan MSTs

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

DefinitionsCommon Algorithms

Applications

Some Applications

Taxonomy

Clustering Analysis

Traveling Salesman Problem Approximation

Varun Ganesan MSTs

Recommended