CS 473 Midterm 2 Questions (April 7, 2009) Spring 2009 You have 90 minutes to answer four of the ﬁve questions. Write your answers in the separate answer booklet. You may take the question sheet with you when you leave. 1. Recall that a tree is a connected graph with no cycles. A graph is bipartite if we can color its vertices black and white, so that every edge connects a white vertex to a black vertex. (a) Prove that every tree is bipartite. (b) Describe and analyze a fast algorithm to determine whether a given graph is bipartite. 2. Describe and analyze an algorithm S HUFFLE ( A [ 1.. n ]) that randomly permutes the input array A , so that each of the n ! possible permutations is equally likely. You can assume the existence of a subroutine R ANDOM ( k ) that returns a random integer chosen uniformly between 1 and k in O ( 1 ) time. For full credit, your S HUFFLE algorithm should run in O ( n ) time. [Hint: This problem appeared in HBS 3½.] 3. Let G be an undirected graph with weighted edges. (a) Describe and analyze an algorithm to compute the
This is the end of the preview. Sign up
access the rest of the document.