hw2_11

hw2_11 - , show that it takes at least ( n ) time to nd out...

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

View Full Document Right Arrow Icon
CSC 7300 Fall 2011 Homework 2 due date 9/26/11, in class, 120 points 1. We are given a set of n pairs bolts and nuts in a box. Each pair is of different size than others. So for each nut there is exactly one fitting bolt. But they are all mixed up so we donot know which nuts fits with which bolt. Our task is find the pair of nut and bolt whose size is median of all the sizes (assume n to be odd). From the naked eye, all the nuts and bolts look the same size. But only if you try out a nut against a bolt, you may find one of three outcomes: (1) the nut is too tight for the bolt or (2) the nut is too loose for the bolt or (3) the nut is exactly fitting the bolt. Give an algorithm to find this median nut-bolt pair and analyse its complexity. In the average case, the algorithm should take no more than O ( n ) nut-bolt-comparisions. (Hint: Use quicksort idea). 2. A two-dimensional array A [1 ..n, 1 ..n ] is called monotonic iff i l and j m implies A [ i,j ] A [ l,m ]. Given a monotonic array A and a number x
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: , show that it takes at least ( n ) time to nd out whether x appears somewhere in A or not. Give also an O ( n ) algorithm. 3. (a) (5 points) Given an array A [1 ..n ] of positive integers such that for all i , A [ i ] < (log n ) log n : how fast can we sort A ? (b) (15 points) You are given an array of integers, where dierent integers may have dierent number of digits, but the total number of digits over all the integers in the array is n . Show how you can sort this array in O ( n ) time. 4. Given an array A , the task is to nd the largest, 2nd largest, 4th largest, 8th largest, 16th largest ,. ..and so on upto 2 b log n c th largest element. Give an O ( n ) algorithm to do this. 5. Given an array A , the task is to nd b n/k c th largest, b 2 n/k c th largest, b 3 n/k c th largest ,.... and so on upto b kn/k c th largest. Give an O ( n log k ) algorithm. 6. Problem 92 (a),(c) on page 194 (or 225) of CLRS. 1...
View Full Document

Ask a homework question - tutors are online