CS 121: Assignment 8

Sorting

Due: Monday, March 24, 10:00 am

20% each.

1) Sort the following array on paper, using Selection Sort. Show the state of the array after each iteration of the outer loop.

(89, 15, 66, 23, 25, 1, 18, 9, 10, 11)

2) On paper, sort the same array as above using Merge Sort. Show the state of the array after each splitting and after each merging. Hint: when calculating where to split the array, consider the exact meaning of the / operator (integer division).

3) Run both Selection Sort and Merge Sort (as implemented in the textbook) on a computer, and use the StopWatch class to measure their runtime in ms for array sizes of 1000, 10,000, 100,000 and 1,000,000 integers. This may take some time. Turn in your measurement results and state what the clock rate of your computer is (in GHz).

4) Exercise P14.1 (page 661).

5) Exercise P14.4. Hint: use the method String. compareTo().



CS 121