Write a multithreaded sorting program in Java that works as follows: A collection of items is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
The following code implements the instructions give public class MultithreadedSort public static voi... View the full answer
Related Book For
Accounting Information Systems basic concepts and current issues
ISBN: 978-0078025334
3rd edition
Authors: Robert Hurt
Posted Date:
Students also viewed these algorithms questions
-
Antelopes, native to Africa and Asia, range in size from 30 cm to over 180 cm at the shoulder, with most between 90-120 cm. This is related to the humerus length. The data below gives the length and...
-
Write a multithreaded sorting program that works as follows: A list of integers is divided into three smaller lists of equal size. Three separate threads (which we will term sorting threads) sort...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
The root cause of underdevelopment and environmental degradation is the overdevelopment of a handful of rich nations. Discuss.
-
Two children are standing on a diving board of mass 65 kg. Knowing that the masses of the children at C and D are 28 kg and 40 kg, respectively, determine (a) The reaction at A, (b) The reaction at B.
-
Mr. Jorgensen, a shareholder in the Best Corporation, owns 200 shares of ts common stock. Mr. Jorgensen receives a 7% stock dividend, After the stock dividend, Mit Jorgensen will have a: O total of...
-
Calculate the median for each of the following sets of data: a. 2, 2, 3, 4, 6, 9,9 b. 7, 7, 8, 12, 13, 14, 17, 21, 23 c. 11, 6, 3, 14, 12, 15, 8, 10, 7 d. 9, 6, 7, 5, 8, 7, 8, 9, 10, 8, 7 e. 10, 13,...
-
The following facts relate to McKane Corporation. 1. Deferred tax liability, January 1, 2010, $60,000. 2. Deferred tax asset, January 1, 2010, $20,000. 3. Taxable income for 2010, $115,000. 4....
-
K On December 31, 2024, when the market interest rate is 12%, McCann Realty issues $900,000 of 13.25%, 10-year bonds payable. The bonds pay interest semiannually. McCann Realty received $964,699 in...
-
The table below shows Crystal's total cost of producing different quantities of tie-dyed t-shirts for a local arts festival. Instructions: Enter your answers as a whole number. a. Complete the...
-
What are the General Properties of Covalent Compounds?
-
Explain why the growth rate of GDP in current prices does not provide information about how quickly the economy is really growing. Chinas real GDP increased 6.9 percent in the first quarter of 2017...
-
After you have studied Economics in the News on pp. 546547, answer the following questions. a. How did the BEA estimates of the real GDP growth rate in the second and third quarters of 2020 change...
-
Explain the special complications involved with attempting to compare the economic welfare in China and the United States by using the GDP for each country. The International Monetary Fund reported...
-
The table in the next column lists some national accounts data for the United States in 2019. a. Calculate U.S. GDP in 2019. b. Explain the approach (expenditure or income) you used to calculate GDP....
-
Compare the distribution of market income with the distribution of money income shown in Fig. 19. 3. Which distribution is more unequal and why? The table shows the distribution of market income in...
-
17) When a mosquito infected with Plasmodium first bites a human, the Plasmodium A) cells infect the human liver cells B) oocyst undergoes meiosis C) cells cause lysing of the human red blood cells...
-
For the following arrangements, discuss whether they are 'in substance' lease transactions, and thus fall under the ambit of IAS 17.
-
Indicate whether each of the following statements is (i) Always true, (ii) Sometimes true, or (iii) Never true. For those that are (ii) Sometimes true, explain when the statement is true. a. The...
-
a. Consider the Richards Furniture Company flowchart again. Describe at least two strengths and at least two weaknesses of the flowchart itself. Then, identify and describe at least two strengths and...
-
a. In your own words, explain the similarities and differences between accounting and bookkeeping. b. What systems do accountants use to create and modify a chart of accounts? c. What internal...
-
Ferns that eject spores generally do so in pairs, with two spores flying off in opposite directions. The structure from which the spores are launched is quite lightweight. If it takes a certain...
-
A dog can provide sufficient power to pull a sled with a 60 N force at a steady 2.0 m/s. Suppose the dog is hitched to a different sled that requires 120 N to move at a constant speed. How fast can...
-
Most of the energy you expend in cycling is dissipated by the drag force. If you double your speed, you increase the drag force by a factor of 4. This increases the power to cycle at this greater...
Study smarter with the SolutionInn App