Problem Set #3

Due: 3pm, Oct 6th, 2008

1. Text problem 2.4.

2. Text problem 2.12.

3. Text problem 2.17.

4. Let A and B be arrays of integers. Each array contains n elements, and each array is in sorted order (ascending). A and B do not share any elements in common. Give a O(log n)-time algorithm which finds the median of A union B. In other words, find the median of the 2n elements given by putting A and B together into one array. (Note: Remember the definition from our book (section 2.4) for the median of a list with an even number of elements.)

5. The text doesn't implement their algorithm for Selection. Please do so. Then, compute the median of the list of words given here using your algorithm. (Note: Use the standard comparison for strings (just like strcmp() in C). All words in this list are distinct.)

• What is the median of the list? Run your program and show the output.
• Run your program 1000 times on the word list and compute the average number of "split" operations you do for each run.

6. (Extra Credit) Don't do this one until you've worked on all others first! This is worth only a few points and is harder than the other problems.     Text problem 2.33.