Homework #2 -- due Monday Wk 3

# required problems topic
1 (Baase Exercise 1.41 on page 65)
Write out the algorithm to find X in an ordered array using the method that compares X to every fourth entry until X itself or an entry larger than X is found, and then, in the latter case, searches for X among the preceding three.  How many element comparisons does your algorithm do in the worst case?
search ordered list
2 (Baase Exercise 4.50 on page 216)
Give an efficient in-place algorithm to rearrange an array of N elements so that all the negative keys precede all the nonnegative keys.  How fast is your algorithm?
sorting
3 CLR Exercise 8.1-4 on page 194
Suppose that you are given a sequence of n elements to sort. The input sequence consists of n/k subsequences, each containing k elements. The elements in a given subsequence are all smaller than the elements in the succeeding subsequence and larger than the elements in the preceding subsequence. Thus, all that is needed to sort the whole sequence of length n is to sort the k elements in each of the n/k subsequences. Show an Ω(n lg k) lower bound on the number of comparisons needed to solve this variant of the sorting algorithm. (Hint: It is not rigorous to simply combine the lower bounds for the individual subsequences.)
sorting lower bound
4 CLR Exercise 6.4-3 on page 160
What is the running time of HEAPSORT on an array A of length n that is already sorted in increasing order? What about decreasing order?
heapsort complexity

# suggested problems topic
5 CLR Exercise 8.1-3 on page 194 lower bound on sorting
6 CLR Exercise 8.2-2 on page 196 stability
7 Baase Exercise 1.50 on page 67 search
8 Baase Exercise 4.37 on page 214 heapsort
9 CLR Exercise 6.1-1 on page 153 heaps
10* Baase Exercise 1.47 on pages 66 searching unknown sized array
11* Linear-time solution for Baase Exercise 4.59a on page 218 maximum profit window in 2D
12* Consider a rectangular array.
Sort the elements in each row into increasing order.
Next sort the elements in each column into increasing order.
Prove that the elements in each row remain sorted.
shellsort basis


Dan Hirschberg
Computer Science Department
University of California, Irvine, CA 92697-3435
dan at ics.uci.edu
Last modified: Jun 26, 2013