cse101_11_21_11

cse101_11_21_11 - 65 f 30 d 29 c 25 a, b 75% = A-63% =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Minimum Spanning trees 1. Definition of MST a. Input: Graph G = (V, E) Edge weights w e Ouput: Tree T = (V, E’), E’ in E Minimize weight(T) = sum from e in E’ w e b. Kruskal’s algorithm A very simple greedy approach: keep adding the next lightest edge that doesn’t create a cycle. Number of edges always n – 1. To check if the edge will create a cycle, check if they are in different connected components c. Implement using a disjoint sets data structure Three operations: Makeset(x): create a set containing just one element x. Find(x): in what set does element x lie Union(x, y): merge the set containing x with the set containing y d. Procedure kruskal(G, w) X = (empty list) For all u in V: Makeset(u) // makes connected components of just one node Sort edges by weight For each (u, w) in E in increasing order of weight: If find(u) != find(w) Add(u, w) to X Union(u, w) Running time O(V + E) + O(E log E) sorting + V x makeset + 2E * find + V – 1 union = O((V+E) log V). note: loge = O(log V) <= 2log(V)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 65 f 30 d 29 c 25 a, b 75% = A-63% = B-42% = C-e. Why does a greedy strategy work here? Suppose weve already added some edges, and they are a part of an MST, which edges can we add next? Cut property: Suppose edges X &lt; E are part of some MST T. pick any subset of nodes S in V such that X has no edges between S and V S. Let e be the lightest edge across cut (S, V S). Then X U {e} is part of some MST T e.i. If e is in T: were done. Otherwise, we will show that there iiis a different MST T that contains e e.ii. Ad e to T T + e: contains a cycle, the cycle must cross the cut with another edge e.look at e.iii. Look at T = T + e e T is connected (removing a cycle edge cannot disconnect a graph) T has V 1 edges Therefore, T is a tree Weight(T) = weight(T) + w e w e &lt;= weight(T) Weight(T) = weight(T) and T is an MST. e.iv....
View Full Document

Page1 / 2

cse101_11_21_11 - 65 f 30 d 29 c 25 a, b 75% = A-63% =...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online