Вы находитесь на странице: 1из 2

Sean Li CS 4820 Notes Spring 2013 Introduction to Design and Analysis of Algorithms Lecture 6 2/1/13 Denitions.

s. An undirected graph G = (V, E) is connected if there is a path between any 2 nodes. We dene an equivalence relation u v if there exists a path between u and v. Equivalance classes are called connected components. A tree is an undirected connected graph graph with no cycles. A forest is an undirected graph with no cycles, not necessarily connected. Given a graph G = (V, E), a spanning tree T is a subset of E such that the graph (V, T ) is a tree. Lemma. A spanning tree on n vertices has has n 1 edges. Stronger Lemma. If a forest has n vertices, m edges, and cc connected components, then n = m + c. Proof. Base case with m = 0 is trivial. In the induction step, adding an edge always connects two commponents (else a cycle is formed). This keeps n = (m + 1) + (c 1) = m + c. Minimum Spanning Trees (MST). Suppose we have a weight function w : E N. A minimum spanning tree T of minimum weight eT w(e). Kruskals Algorithm. Start with T which has no edges. Sort the edges by weight. For each edge e in increasing order of weight, if T = T {E} has no cycles, then set T as the tree. Else, discard. Repeat the previous step until |T | = n 1. Prims Algorithm. Start with X = s (an arbitrary vertex), s V , T = . Sort the edges A adjoined to X by weight.

Let e A be the element of minimum weight, and let y be the end of e that is not already in X. Set X := X {y}. Repeat the previous step until |X| = n. Subtractive Algorithm. Start with G = (V, E). Repeat: Find a cycle. Take a maximum-weight edge on the cycle and delete it. Blue/Red Algorithm. Very general algorithm that describes Kruskals, Prims, and the subtractive algorithm. Dene a cut in G to be a partition of V into 2 disjoint sets X, Y whose union is V . Blue Rule: Find a cut with no blue edge crossing the cut. Take an uncolored edge crossing the cut of minimum weight. Color it blue. Red Rule: Find a cycle with no red edge. Take an uncolored edge on the cycle of maximum weight, and color it red. Apply the two rules in any order until all the edges are colored. The blue edges always form a spanning tree. Ecient Implementation of Prims Algorithm. Use a priority queue with binary heap. Insert an element with priority, extract minimum. Runs in O(n log n) for n inserts and extracted minimums.

Page 2

Вам также может понравиться