MIT1_204S10_lec11

# MIT1_204S10_lec11 - 1.204 Lecture 11 Greedy algorithms: Mi...

This preview shows pages 1–5. Sign up to view the full content.

1.204 Lecture 11 Greedy algorithms: Minimum spanning trees Minimum spanning tree If G is an undirected, connected graph, a subgraph T of G is a spanning tree iff T is a tree with n nodes (or, equivalently, n-1 arcs) A minimum spanning tree is the spanning tree T of G with minimum arc costs 1 1 6 5 4 7 2 3 3 7 6 5 4 10 25 22 24 14 28 16 18 12 25 22 12 16 14 10 A graph and its minimum cost spanning tree (a) (b) 1 2 Figure by MIT OpenCourseWare.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Applications of minimum spanning trees Building wiring, mechanicals Water, power, gas, CATV, phone, road distribution networks Copper (conventional) phone networks MST algorithms not needed, done heuristically Wireless telecom networks Cell tower connectivity with microwave ‘circuits’ Cost is not a function of distance, but reliability is dt th (i East-westli t links preferred to north th-south (ice, sun,…) Topography matters: DEM data Move to fiber optics as better technology Problem is to have a cost-effective, reliable network Not to find the minimum spanning tree System engineer looks at entire issue MST is one component of a broader solution Prim’s algorithm Greedy method to build minimum spanning tree Start at an arbitrary node (root) The set of arcs selected always form a tree T Initially the tree T is just the root. No arcs added to it yet. The next arc (u,v) to be included in T is: Minimum cost arc such that Both nodes u and v are not in T already Add arc (u,v) and node v to T Mark node v as being in T, or visited (u is already in the tree) End when all nodes in tree have been visited, or Equivalently, when (n-1) arcs have been put in the spanning tree {(u,v)} is now the new tree T ׫ T 2
Prim’s algorithm example Standard Prim: data members, constructor public class Prim { // Assumes connected graph; not checked private int nodes; // Assumes consecutive node numbers private int[] head; private int[] to; private int[] dist; private int[] P; // Predecessor node back to root private boolean[] visited; // Has node been visited private int MSTcost; Prim(int n int[] h int[] t int[] d) { Prim(int n, int[] h, int[] t, int[] d) { nodes = n; // Or set nodes= head.length-1 head = h; to = t; dist = d; } 3 1 10 10 25 24 22 18 10 25 22 12 10 10 25 25 22 22 12 12 16 14 16 14 12 16 28 10 25 25 22 10 1 6 5 4 7 3 6 1 2 5 4 3 7 6 1 1 1 1 2 2 2 2 3 3 3 3 7 7 5 5 7 7 6 6 6 6 5 5 4 4 4 4 7 5 4 2 3 2 Stages in Prim's Algorithm (a) (b) (c) (f) (e) (d) Figure by MIT OpenCourseWare.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Standard Prim: prim(), p.1 public int prim(int root) {
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/04/2011 for the course ESD 1.204 taught by Professor Georgekocur during the Spring '10 term at MIT.

### Page1 / 13

MIT1_204S10_lec11 - 1.204 Lecture 11 Greedy algorithms: Mi...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online