{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW2sol_001 - COT 5405 Analysis of Algorithms Spring 2010...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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 e is the costliest edge in cycle C , but here’s a tiny caveat: we need to demonstrate that this new structure T 1
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern