# Minimum Spanning Tree

**Topics:**Graph theory, Minimum spanning tree, Greedy algorithm

**Pages:**29 (2477 words)

**Published:**September 26, 2012

MST. Given connected graph G with positive edge weights, find a min weight set of edges that connects all of the vertices.

Minimum Spanning Tree

24

4

23

6

9

18

•

•

•

•

•

•

•

5

introduction

Weighted graph API

cycles and cuts

Kruskal’s algorithm

Prim’s algorithm

advanced algorithms

clustering

11

16

8

10

14

7

21

G

References: Algorithms in Java (Part 5), Chapter 20

Intro to Algs and Data Structures, Section 5.4

Copyright © 2007 by Robert Sedgewick and Kevin Wayne.

3

Minimum Spanning Tree

MST. Given connected graph G with positive edge weights, find a min weight set of edges that connects all of the vertices.

24

4

introduction

weighted graph API

cycles and cuts

Kruskal’s algorithm

Prim’s algorithm

advanced algorithms

clustering

23

6

9

18

5

11

16

8

10

14

7

21

cost(T) = 50

Brute force: Try all possible spanning trees

problem 1: not so easy to implement

problem 2: far too many of them

!

!

Ex: [Cayley, 1889]: VV-2 spanning trees on the complete graph on V vertices. 2

4

MST Origin

Medical Image Processing

Otakar Boruvka (1926).

Electrical Power Company of Western Moravia in Brno.

Most economical construction of electrical power network.

Concrete engineering problem is now a cornerstone problem in combinatorial optimization.

MST describes arrangement of nuclei in the epithelium for cancer research

!

!

!

Otakar Boruvka

http://www.bccrc.ca/ci/ta01_archlevel.html

5

7

Applications

MST is fundamental problem with diverse applications.

!

!

!

!

Network design.

– telephone, electrical, hydraulic, TV cable, computer, road Approximation algorithms for NP-hard problems.

– traveling salesperson problem, Steiner tree

Indirect applications.

– max bottleneck paths

– LDPC codes for error correction

– image registration with Renyi entropy

– learning salient features for real-time face verification – reducing data storage in sequencing amino acids in a protein – model locality of particle interactions in turbulent fluid flows – autoconfig protocol for Ethernet bridging to avoid cycles in a network Cluster analysis.

6

http://ginger.indstate.edu/ge/gfx

8

Two Greedy Algorithms

Weighted Graph Interface

Kruskal's algorithm. Consider edges in ascending order of cost. Add the next edge to T unless doing so would create a cycle.

public class WeightedGraph

(graph data type)

WeightedGraph(int V)

Prim's algorithm. Start with any vertex s and greedily grow a tree T from s. At each step, add the cheapest edge to T that has exactly one endpoint in T.

void insert(Edge e)

Iterable adj(int v)

int V()

String toString()

create an empty graph with V vertices

insert edge e

return an iterator over edges incident to v

return the number of vertices

return a string representation

Theorem. Both greedy algorithms compute an MST.

for (int v = 0; v < G.V(); v++)

{

for (Edge e : G.adj(v))

{

int w = e.other(v);

// edge v-w

}

}

Greed is good. Greed is right. Greed works. Greed

clarifies, cuts through, and captures the essence of the

evolutionary spirit." - Gordon Gecko

iterate through all edges (once in each direction)

9

11

Edge data type

public class Edge implements Comparable

{

public final int v, int w;

public final double weight;

public Edge(int v, int w, double weight)

{

this.v = v;

this.w = w;

this.weight = weight;

}

introduction

weighted graph API

cycles and cuts

Kruskal’s algorithm

Prim’s algorithm

advanced algorithms

clustering

public int either()

{ return v; }

public int other(int vertex)

{

if (vertex == v) return w;

else return v;

}

10

public int compareTo(Edge f)

{

Edge e = this;

if

(e.weight < f.weight) return -1;

else if (e.weight > f.weight) return +1;

else if (e.weight > f.weight) return 0;

}

}

12

Weighted graph: Java...

Please join StudyMode to read the full document