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% (QA)
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...
-
The following data show residential and commercial natural gas consumption (quadrillion Btu) from 1985 through 2000. a. Construct a graph of the time series, then superimpose a three-year centered...
-
What are the two categories of data mining and knowledge discovery software?
-
Holiday Fruit Company buys oranges and processes them into gift fruit baskets and fresh juice. The company grades the fruit it buys on a scale from 1 (lowest quality) to 5 (highest quality). The...
-
Given the Entity Relationship model below. Use it to answer the questions that follow b) Transform the above model into a relational model. Productid Orderld OrderDate ProductDescription Quantity...
-
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...
-
An airplane has a mass of 2.0 X 106 kg, and the air flows past the lower surface of the wings at 95m/s. If the wings have surface area of 1200m2, how fast must the air flow over the upper surface of...
-
how to Evaluate the Editorial. Comment on the appropriateness of the editorial, and its fairness, bias, representation, and timeliness. Express your personal views of the editorial and whether or not...
-
A 35-year-old right-handed mechanic comes to the clinic with progressive right hand weakness. The patient frequently uses a screwdriver to perform his duties at work. On neurologic examination,...
-
My boss cut my hours back at work and I've got to cut my spending.I decide to get rid of one of the three streaming services I have - Netflix, Hulu or Disney.I decide on Hulu.I call Hulu to cancel,...
-
What implications arise from the presence of agglutination or hemolysis during the immediate spin phase of the crossmatch procedure?
-
Alexander is considering making an investment in a major mining company. Below table estimates on the probable returns on the investment. Calculate: . Probability 0.20 0.15 0.15 0.30 0.20 Alexander's...
-
eBay Inc. operates an Internet-based community in which buyers and sellers are brought together to buy and sell almost anything. The eBay online service permits sellers to list items for sale, buyers...
-
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...
-
What class of laws did local governments pass to empower police departments to regulate groups' right to be in public life?
-
In one week, Gina spent x minutes on the internet. Sammy spent 15 minutes less than Gina. (a) Write down an expression for how long Sammy spent on the internet.
-
How should multinational corporations formulate and execute global expansion strategies that balance standardization and localization, considering diverse cultural, regulatory, and market-specific...
Study smarter with the SolutionInn App