Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

Step: 1

The following code implements the instructions give public class MultithreadedSort public static voi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems basic concepts and current issues

Authors: Robert Hurt

3rd edition

130855849X, 978-1308558493, 78025338, 978-0078025334

More Books

Students also viewed these Algorithms questions