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...
-
Learning Objectives 4, 5, 6: Analyze the impact of business transactions on accounts; record (journalize and post) transactions in the books; construct and use a trial balance) During the first month...
-
The correlation coefficient of \(x\) and \(y\) is given by a. \(\sigma_{x y}\) b. \(\sigma_{x y} /\left(\sigma_{x} \sigma_{y} ight)\) c. \(\sigma_{x} \sigma_{y}\)
-
The Mon Elisa Museum of Fine Arts is an NFPO that derives most of its resources from wealthy patrons. Mon Elisa has recently changed its accounting system to eliminate the use of separate funds. All...
-
Evaluate the following definite integral. 1 x (4x 1)4 dz 0 1/3 X
-
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...
-
Discuss Scott McNealys comments about sentiment in his interview with Fortune magazine. In your answer, describe any valuation metric Scott McNealy mentions. Do McNealys comments suggest that Sun...
-
You are the owner of a middle-sized Company (with the annual turnover of Euro 5 min) and came to the meeting with your lending bank with the intention to increase your loan portfolio. At the meeting...
-
Hawaii Surf shop has a retail store on Oahu selling surfboards and other surf apparel. Their GET license is GE 123-111-5523-01. And the last 4 digits of their EIN is 8825 They had the following sales...
-
One of the points of discussion between management and its consultants is the choice of the discount rate for this capital budgeting exercise. It was finally decided that the discount rate would be...
-
Using a regression analysis, I need help forecasting total losses - no incident rate or severity rate is needed. Show data, graphs and regression output. Accident Year Period Claims Frequency 5 9 10...
-
You are working at an industrial supplier, Great Gadgets. You are planning to purchase a truck for work purposes. The truck costs $60,000 to purchase. You plan to use it for five years. After five...
-
Find each resultant vector R. Give R in standardposition. 10.0 mi 16.5 mi
-
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...
-
Perform the indicated operations of the given matrices: 1. sum = A +B 2. difference1 B-A 3. difference2A-B -5 1 = [1, 1] A= 41 B = 6-3 2 3
-
5. Use MATLAB to solve the following system of 3 linear equations in unknowns x, y and z. 4x+3y+2z = 44 5x+5y+7x=71 X+ Z = 11 Note that these equations can be written in matrix form as A x=b, where...
-
You purchase a 4-pound case of Portobello mushrooms for $23.49. The yield percent for mushrooms is 93%. How much would 1 kilogram of cleaned mushrooms cost?
Study smarter with the SolutionInn App