Java Reference
In-Depth Information
30.13
( Generic parallel merge sort ) Revise Listing 30.10, ParallelMergeSort.java, to
define a generic parallelMergeSort method as follows:
public static <E extends Comparable<E>> void
parallelMergeSort(E[] list)
*30.14
( Parallel quick sort ) Implement the following method in parallel to sort a list
using quick sort (see Listing 23.7).
public static void parallelQuickSort( int [] list)
Write a test program that times the execution time for a list of size 9,000,000
using this parallel method and a sequential method.
*30.15
( Parallel sum ) Implement the following method using Fork/Join to find the
sum of a list.
public static double parallelSum( double [] list)
Write a test program that finds the sum in a list of 9,000,000 double values.
*30.16
( Parallel matrix addition ) Programming Exercise 8.5 describes how to perform
matrix addition. Suppose you have multiple processors, so you can speed up the
matrix addition. Implement the following method in parallel.
public static double [][] parallelAddMatrix(
double [][] a, double [][] b)
Write a test program that measures the execution time for adding two
2,000
2,000 matrices using the parallel method and sequential method,
respectively.
*
*30.17
( Parallel matrix multiplication ) Programming Exercise 7.6 describes how to
perform matrix multiplication. Suppose you have multiple processors, so you
can speed up the matrix multiplication. Implement the following method in
parallel.
public static double [][] parallelMultiplyMatrix(
double [][] a, double [][] b)
Write a test program that measures the execution time for multiplying two
2,000
2,000 matrices using the parallel method and sequential method,
respectively.
*
*30.18
( Parallel Eight Queens ) Revise Listing 22.11, EightQueens.java, to develop a
parallel algorithm that finds all solutions for the Eight Queens problem. ( Hint :
Launch eight subtasks, each of which places the queen in a different column in
the first row.)
Comprehensive
***30.19
( Sorting animation ) Write an animation for selection sort, insertion sort, and
bubble sort, as shown in FigureĀ 30.31. Create an array of integers 1 , 2 , . . . ,
50 . Shuffle it randomly. Create a pane to display the array in a histogram. You
should invoke each sort method in a separate thread. Each algorithm uses two
nested loops. When the algorithm completes an iteration in the outer loop, put
the thread to sleep for 0.5 seconds, and redisplay the array in the histogram.
Color the last bar in the sorted subarray.
 
 
Search WWH ::




Custom Search