You are on page 1of 1

CS 302 Design & Analysis of Algorithms Kamran Azam

Assignment # 2
Due: Tuesday, Oct 05 in class

Problem 2.1

Given an array A containing n non-negative integers where A[i] ≤ U, describe an


algorithm which does some processing on the given input in time Θ(n + U) and then
answers questions of the kind “how many of the given n integers fall into a range [p, q]?”
in constant time.

Problem 2.2

Can you sort n integers in the range 0 to 2n in Θ(n) time? If yes, give an algorithm. If not,
why not?

Problem 2.3
Show that the second smallest of n elements can be found with n +┌ lgn ┐ - 2
comparisons in the worst case. You are not allowed to use heaps or any sorting
procedure. Come up with a selection algorithm based on tournament method. Give details
and justification.

You might also like