Java Reference
In-Depth Information
Section 23.8
*23.14
( Execution time for external sorting ) Write a program that obtains the execution
time of external sorts for integers of size 5,000,000, 10,000,000, 15,000,000,
20,000,000, 25,000,000, and 30,000,000. Your program should print a table
like this:
File size
5,000,000
10,000,000
15,000,000
20,000,000
25,000,000
30,000,000
Time
Comprehensive
*23.15
( Selection sort animation ) Write a program that animates the selection sort
algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in
a random order. The array elements are displayed in a histogram, as shown in
Figure 23.20a. Clicking the Step button causes the program to perform an itera-
tion of the outer loop in the algorithm and repaints the histogram for the new
array. Color the last bar in the sorted subarray. When the algorithm is finished,
display a message to inform the user. Clicking the Reset button creates a new
random array for a new start. (You can easily modify the program to animate the
insertion algorithm.)
(a)
(b)
F IGURE 23.20
(a) The program animates selection sort. (b) The program animates bubble sort.
*23.16
( Bubble sort animation ) Write a program that animates the bubble sort algo-
rithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a
random order. The array elements are displayed in a histogram, as shown in
Figure 23.20b. Clicking the Step button causes the program to perform one com-
parison in the algorithm and repaints the histogram for the new array. Color the
bar that represents the number being considered in the swap. When the algorithm
is finished, display a message to inform the user. Clicking the Reset button cre-
ates a new random array for a new start.
*23.17
( Radix sort animation ) Write a program that animates the radix sort algorithm.
Create an array that consists of 20 random numbers from 0 to 1,000. The array
elements are displayed, as shown in Figure  23.21. Clicking the Step button
causes the program to place a number in a bucket. The number that has just
been placed is displayed in red. Once all the numbers are placed in the buckets,
clicking the Step button collects all the numbers from the buckets and moves
 
Search WWH ::




Custom Search