# lec8 - CS 323 Lecture 8 Design and Analysis of Algorithms...

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

n CS 323 ± ± Lecture 8 o Design and Analysis & of Algorithms Hoeteck Wee · [email protected] http://www.cs.qc.edu/~hoeteck/f09/

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

View Full Document
Homework 3 Question 3 QUESTION. what does a = [[]] * 5 mean in Python? Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) >>> a = [1] * 5 >>> a[0] = 2 >>> a [2, 1, 1, 1, 1] >>> a = [[1]] * 5 >>> a[0].append(1) >>> a [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]] Hoeteck Wee CS 323 Sep 28, 2009 2 / 13
Minimum spanning tree PROBLEM. minimum spanning tree (MST) problem I input: a set of locations V = { v 1 , . . . , vn } , with costs for building a (undirected) link between some pairs of locations I goal: build the cheapest communication network s.t. every pair of locations is connected (cost of a network = sum of link costs) a b c d e f g 7 8 5 9 7 5 15 6 8 9 11 FACTS. I removing any edge from a cycle in a connected graph leaves the graph connected. I every n -node tree has exactly n - 1 edges. I the complete graph Kn has n n - 2 spanning trees. Hoeteck Wee CS 323 Sep 28, 2009 3 / 13

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

View Full Document
Kruskal’s MST algorithm ALGORITHM. incrementally add least cost edges that do not make a cycle sort edges by cost, T = [] for e in edges: if adding e to T does not create a cycle: T.append(e) return T a b c d e f g 7 8 5 9 7 5 15 6 8 9 11 1. add ( a , d ) 2. add ( c , e ) 3. add ( d , f ) 4. add ( a , b ) 5. add ( b , e ) 6. add ( e , g ) Hoeteck Wee CS 323 Sep 28, 2009 4 / 13
Kruskal’s MST algorithm CLAIM. ﬁrst i selected edges are part of some MST, i = 0 , 1 , . . . , n - 1 .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/31/2010 for the course COMPUTER S 700 taught by Professor Joewhite during the Spring '10 term at Universidad San Martín de Porres.

### Page1 / 13

lec8 - CS 323 Lecture 8 Design and Analysis of Algorithms...

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

View Full Document
Ask a homework question - tutors are online