Demonstrated the recursive merge sort algorithm. Reimplement the program of Fig. 19.6 using the Fork/Join Framework. Fig.
Question:
Demonstrated the recursive merge sort algorithm. Reimplement the program of Fig. 19.6 using the Fork/Join Framework.
Fig. 19.6
Transcribed Image Text:
I // Fig. 19.6: MergeSortTest.java // Sorting an array with merge sort. import java.security.SecureRandom; 2 4 import java.util.Arrays; 6 public class MergeSortTest { 7 12 14 15 16 17 18 19 20 27 28 29 30 31 32 33 35 36 37 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 III 112 113 114 } // calls recursive sortArray method to begin merge sorting public static void mergeSort (int[] data) { sortArray (data, 0, data.length - 1); // sort entire array } // splits array, sorts subarrays and merges subarrays into sorted array private static void sortArray (int[] data, int low, int high) { // test base case; size of array equals 1 } } // merge two sorted subarrays into one sorted subarray private static void merge(int[] data, int left, int middlel, int middle2, int right) { split: split: merge: merge: split: merge: merge: split: split: split: merge: if ((high low) >= 1) { // if not base case. int middle1 = (low + high) / 2; // calculate middle of array int middle2 = middlel + 1; // calculate next element over merge: } } // method to output certain values in array private static String subarrayString(int[] data, int low, int high) { StringBuilder temporary = new StringBuilder(); split: merge: // output split step System.out.printf("split: subarrayString(data, System.out.printf(" subarrayString(data, System.out.printf(" subarrayString(data, middle2, high)); //split array in half; sort each half (recursive calls) sortArray (data, low, middlel); // first half of array sortArray (data, middle2, high); // second half of array merge: } public static void main(String[] args) { SecureRandom generator = new SecureRandom(); merge: // merge two sorted arrays after split calls return merge (data, low, middlel, middle2, high); int leftIndex = left; // index into left subarray int rightIndex = middle2; // index into right subarray int combinedIndex = left; // index into temporary working array int[] combined = new int[data.length]; // working array } Unsorted array: [75, 56, 85, 90, 49, 26, 12, 48, 40, 47] split: split: 75 56 85 90 49 75 56 85 // output two subarrays before merging System.out.printf("merge: %s%n", subarrayString(data, left, middlel)); System.out.printf(" %s%n", subarrayString(data, middle2, right)); // merge arrays until reaching end of either while (leftIndex
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
The image youve provided seems to show a traditional merge sort implementation in Java To reimplemen...View the full answer
Answered By
Anurag Agrawal
I am a highly enthusiastic person who likes to explain concepts in simplified language. Be it in my job role as a manager of 4 people or when I used to take classes for specially able kids at our university. I did this continuously for 3 years and my god, that was so fulfilling. Sometimes I've skipped my own classes just to teach these kids and help them get their fair share of opportunities, which they would have missed out on. This was the key driver for me during that time. But since I've joined my job I wasn't able to make time for my passion of teaching due to hectic schedules. But now I've made a commitment to teach for at least an hour a day.
I am highly proficient in school level math and science and reasonably good for college level. In addition to this I am especially interested in courses related to finance and economics. In quest to learn I recently gave the CFA level 1 in Dec 19, hopefully I'll clear it. Finger's crossed :)
4.80+
2+ Reviews
10+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
In Exercises 23.2023.21, you reimplemented recursive sorting algorithms using the Fork/Join Framework. Why might you not want to invest the effort into applying this technique to a recursive binary...
-
The recursive merge sort algorithm uses binary recursion. (T / F)
-
write code for merge sort algorithm for a 1*15 array without using recursive logic discuss about the computational cost of a non-recursive merge sort algorithm with a merge sort algorithm that is...
-
In Exercises 912, use the given conditions to write an equation for each line in point-slope form and general form Passing through (4, -7) and perpendicular to the line whose equation is x - 2y - 3 =...
-
(a) Use the result of Problem 42.38 to calculate the equilibrium separation of the atoms in HC1 molecule. The mass of a chlorine atom is 5.81 x 10-26 kg, and the mass of a hydrogen atom is 1.67 x...
-
An addictions researcher was curious about which drug was hardest to quit: alcohol, cigarettes, or heroin. She obtained samples of alcoholics, smokers, and heroin addicts who were in treatment for...
-
\(4+(8+\sqrt{7})=(4+8)+\sqrt{7}\) Identify the property of real numbers that is being illustrated.
-
Vogel Co. produces three models of heating and air conditioning thermostat components. The following table summarizes data about each model: Required: a. Criticize the preceding presentation. On what...
-
Question 1 When will the geometric average annual rate of return be equal to the arithmetic average annual rate of return? (A) When all the annual returns are positive (B) The geometric average ann...
-
In Exercise 19.10 , you implemented the recursivequicksort algorithm. Reimplement the quicksort using the Fork/Join Framework. Exercise 19.10 The basic algorithm seems simple enough, but how do we...
-
Used map and sum to calculate the sum of the squares of an IntStreams values. Reimplement stream pipeline in Fig. 17.9 to replace map and sum with the following reduce, which receives a lambda that...
-
Describe the two methods that taxpayers use to prepay their taxes.
-
What sophisticated methodologies and tools can Change Management practitioners employ to diagnose the multi-dimensional drivers of organizational change resistance, discerning between cognitive,...
-
Hampton Muffins sells its muffins to restaurants and coffee houses for an average selling price of $26 per case. The following information relates to the budget for Hampton Muffins for this year (all...
-
4. A Frisbee is lodged in a tree branch 6.3mabove the ground. A rock thrown from below must be going at least 3.0m/sto dislodge the Frisbee. a) How fast must such a rock be thrown upward if it leaves...
-
When you have solved your original exam, compute the following, showing all the steps in your work and explaining in full detail why you are making those decisions (a) (t + csc cot (t) + e 15t) dt...
-
A rabbit and a turtle run a 100-meter race. They start at the same point at the same time. The rabbit accelerates at a constant rate of 10 m/s^2for 1 second, then runs at a constant speed for 5...
-
Where, on the Kohlberg framework would you place your own usual motivation for making decisions?
-
How will relating product contribution margin s to the amount of the constrained resource they consume help a company maximize its profits?
-
An analog signal has a bandwidth of 20 KHz. If we sample this signal and send it through a 30 Kbps channel, what is the SNRdB?
-
Distinguish between a link and a channel in multiplexing.
-
Show the contents of the five output frames for a synchronous TDM multiplexer that combines four sources sending the following characters. Note that the characters are sent in the same order that...
-
Listen The desire of foreign producers to preserve market share for goods sold in the United States helps contribute to complete exchange-rate pass-through following a depreciation of the dollar True...
-
You work at a large department store selling computer products. Iwina walks in and wants to buy a wireless router. She explains that the media streaming device she ordered online supports a...
-
Discuss the security issues surrounding the ability of users to access the network from a remote location. Explain the remote access technologies, protocols, and options. Compare VPN technology from...
Study smarter with the SolutionInn App