This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 577: Introduction to Algorithms 11/28/06 Homework Solution: 5a Instructor: Shuchi Chawla TA: Siddharth Barman Question 1 The idea is to follow a clone of randomized quicksort. We have a set of nuts N and a set of bolts B . First we pick an element i of N uniformly at random and partition B using i , i.e. B − is the set of bolts of size less than i and B + is the set of bolts of size greater than i . i serves as a future reference if the sizes of the two partitioned sets B − and B + are comparable, in particular if min { B −  ,  B + } ≥ 1 4  B  then we will use i and the matching bolt later. If the element picked does not satisfy the size constraints (of the partitioned sets) we randomly pick another. Note that any “wellcentered” (pp. 730 of text) element satisfies this property and hence the expected number of steps before we find such an element is 2. We set N = N − { i } and partition N in N − and N + using the matching bolt of i . Note that  N −  =  B −  and  N +  =  B +  . We recursively apply the same strategy to the two partitions. Note that the partition tree we construct is balanced on an average. Formally going down the tree the size of the sets decrease at least by a factor of 3 / 4. Hence if  B j  = n ( 3 4 ) m its depth is at most m . Hence time T spent on j ∈ N j is n ( 3 4 ) m . We have that the number of bolt set of size n ( 3 4 ) m is bounded by ( 4 3 ) m +1 . Hence total time spent for each type m is T × ( 4 3 ) m +1 = 4 3 n . As m is bounded by log n total time spent in expectation is O ( n log n ). Question 2 2a The strategy is to wait for the first half of the bids and determine the maximum among them. So we do not sell before we get to n 2 th bidder but we keep track of the max. bid seen so far say b max . After which we sell to the first bidder with a bid of more than b max in the second half....
View
Full
Document
This note was uploaded on 02/17/2011 for the course CS 577 taught by Professor Joseph during the Spring '08 term at University of Wisconsin.
 Spring '08
 JOSEPH
 Algorithms, Sort

Click to edit the document details