HW2sol_001 - COT 5405 Analysis of Algorithms Spring 2010 Homework 2 Due Friday March 5 2010 12:00pm Notes • You may hand the homework to TAs

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: COT 5405 Analysis of Algorithms, Spring 2010. Homework 2 Due Friday, March 5 2010, 12:00pm. Notes • You may hand the homework to TAs during office hours. You may also hand the homework to Prof. Ranka in class. No late submissions. • To force you to write succinctly, we have enforced page limits. These are noted in front of each question. • Answer each question on a fresh page. • If the problem necessitates writing an algorithm, you must first informally describe the algorithm, in brief, in a paragraph. You can choose to follow this up with pseudocode that formally describes the algorithm. We will peruse your pseudocode only if your English description is not clear. • Write your name on the top right hand corner of your homework. Be sure to write your last name as the last word in your name. • If you are designing an algorithm, you must write a formal proof of correctness. • Please write legibly. 1. [1 page] (15pts) Consider a connected graph with n vertices and exactly n + 43 edges, all with distinct positive weights on them. Your task is to build a minimum spanning tree for this graph in O ( n ) time. Solution: A tree with n vertices can have at the most n- 1 edges, and hence converting this graph to any tree will require deletion of 44 edges from the graph. To build an MST, we need to delete 44 edges with the highest possible cost, taking care to ensure that the graph does not get disconnected at any stage. But this is inefficient. Instead, we can do the following: (1) Run a BFS on this graph with a small modification that the BFS stops the moment a cycle of 3 or more vertices is detected. This can be done easily by keeping a ‘visited’ flag for each vertex and turning it to ‘on’ whenever that vertex is visited. If your BFS procedure happens to visit a vertex whose flag was already turned on, you know that you hit a cycle of three or more vertices, if you also keep a list of vertices visited by the BFS procedure in memory. (2) Once you have the cycle, delete the highest cost edge from this cycle. (3) Repeat steps (1) and (2) 44 times. Step (2) makes use of the cycle property, i.e. in any cycle C in G , the highest cost edge in C cannot be part of any MST. Step (1) takes O ( n + e + e ) = O ( n +2( n +43)) = O ( n ) time. Step (2) takes O ( n ) time to find the highest cost edge in the cycle. Steps (1) and (2) are repeated 44 times, and hence the overall time is O ( n ). Now what remains is to prove the cycle property. So let’s assume that some edge e is the costliest edge in cycle C of G . Let’s further assume that e is part of a spanning tree T of G . We will now prove 1 that T can’t be an MST of G , as follows: We create a new tree T 1 obtained by deleting e from T and adding in edge e 1 from cycle C (which was absent in T- and note that such an edge must certainly exist else T wouldn’t be a tree), and showing that the total cost of T 1 is less than that of T . Note that you may feel that we’ve already completed the proof because...
View Full Document

This note was uploaded on 01/15/2012 for the course COT 5405 taught by Professor Ungor during the Fall '08 term at University of Florida.

Page1 / 5

HW2sol_001 - COT 5405 Analysis of Algorithms Spring 2010 Homework 2 Due Friday March 5 2010 12:00pm Notes • You may hand the homework to TAs

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

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