Question: Write a multithreaded sorting program in Java that works as follows: A collection of items is divided into two lists of equal size. Each

Write a multithreaded sorting program in Java that works as follows: A

 

Write a multithreaded sorting program in Java that works as follows: A collection of items is divided into two lists of equal size. Each list is then passed to a separate thread (a sorting thread), which sorts the list using any sorting algorithm (or algorithms) of your choice. The two sorted lists are passed to a third thread (a merge thread), which merges the two separate lists into a single sorted list. Once the two lists have been merged, the complete sorted list is output. If we were sorting integer values, this program should be structured as illustrated in the diagram below. To ensure that the two sorting threads have completed execution, the main thread will need to use the join() method on the two sorting threads before passing the two sorted lists to the merge thread. Similarly, the main thread will need to use join() on the merge thread before it outputs the complete sorted list (if it is a small list). Also measure the elapsed time of your multithreaded sort application and compare with the sequential equivalent. For reference, my sequential sort of an array of length 800,000 took 110 milliseconds, and the multithreaded version took 72 milliseconds using my laptop. Write helper methods to generate the random array of integers of any length to be sorted, to check if your final array is sorted correctly, and any other method you need. Sorting Thread Original List 7, 12, 19, 3, 18, 4, 2, 6, 15, 8 7, 12, 19, 3, 18 Sorting Thread, 4, 2, 6, 15, 8 Merge Thread 2, 3, 4, 6, 7, 8, 12, 15, 18, 19 Sorted List

Step by Step Solution

3.42 Rating (177 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The following code implements the instructions give public class MultithreadedSort public static voi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!