hbs7 - same size, so we cant tell whether one bolt is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 473: Algorithms, Fall 2010 HBS 7 Problem 1. [Selection on Sorted arrays] Suppose you are given two sorted arrays A [1 ...n ] and B [1 ...m ] and an integer k . Describe an algorithm to find the k th smallest element in the union of A and B in Θ(log( m + n ) time. For example, given the input A [1 ... 8] = [0 , 1 , 6 , 9 , 12 , 13 , 18 , 20] B [1 ... 5] = [2 , 5 , 8 , 17 , 19] k = 6 Your algorithm should return 8. Assume the array contains no duplicates. [Hint: What can we learn by comparing an element of A to an element of B? ] Problem 2. [Nuts and Bolts] Suppose we are given n nuts and n bolts of different sizes. Each nut matches exactly one bolt and vice versa. The nuts and bolts are all almost exactly the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: same size, so we cant tell whether one bolt is smaller than the other, or if one nut is bigger than the other. If we try to match a nut with a bolt, it would be either too big or too small for the bolt or it would be just right for the bolt. Find the correct matchings in worst case expected O ( n log n ) time. [Hint:If a nut and bolt dont match how can you partition the nuts using the bolt and the bolts using the nut? ] 1...
View Full Document

Ask a homework question - tutors are online