In Exercises 23.2023.21, you reimplemented recursive sorting algorithms using the Fork/Join Framework. Why might you not want
Question:
In Exercises 23.20–23.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 search algorithm?
Exercise 23.20
Demonstrated the recursive merge sort algorithm. Reimplement the program of Fig. 19.6 using the Fork/Join Framework.
Fig. 19.6
Exercise 23.21
Implemented the recursive quicksort algorithm. Reimplement the quicksort using the Fork/Join Framework.
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: } // method to output certain values in array private static String subarrayString(int [] data, int low, int high) { StringBuilder temporary = new StringBuilder (); 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: } split: } public static void main(String[] args) { SecureRandom generator = new SecureRandom(); merge: // output split step System.out.printf("split: %s%n". subarrayString (data, low, high)); System.out.printf(" %s%n". subarrayString (data, low, middlel)); System.out.printf(" %s%n%n", 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: // merge two sorted arrays after split calls return merge (data, low, middlel, middle2, high); merge: 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: // 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)
java import javautilconcurrentRecursiveAction import javautilconcurrentForkJoinPool public class Par...View the full answer
Answered By
Rahul Sorout
I'm Rahul Sorout. I graduated from high school with an 80% overall and a 99% in Mathematics. I am in my last year of graduation with Math. Also, I am working as a tutor of Mathematics and subject matter expert of Calculus on online platforms. I am very interested and have extensive knowledge in Mathematics ( Calculus, Algebra, Trigonometry, Statistics and probability etc.). I speak English and Hindi.
0.00
0 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
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
You have just met a new client, Darth Garbinsky, who has come to you for some accounting advice. The thing you have to understand, David, is how these stage plays work. You start out with just an...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Solve the equation (a) Graphically, (b) Numerically, and (c) Symbolically. Then solve the related inequality. |4x7| = 5, |4x - 7| 5
-
Consider a gas of diatomic molecules (moment of inertia I) at an absolute temperature T. If Eg is a ground-state energy and E ex is the energy of an excited state, then the Maxwell-Boltzmann...
-
There is an old saying: Crime doesn't pay. However, for David Miller crime paid for two Mercedes-Benz sedans; a lavish suburban home; a condominium at Myrtle Beach; expensive suits; tailored and...
-
What is an autocorrelation function?
-
The transactions completed by PS Music during June 2012 were described at the end of Chapter 1. The following transactions were completed during July, the second month of the businesss operations:...
-
If the 5- and 5.5-year par yields are both at 2%, compute the forward rate from 5 to 5.5 years.
-
Using the techniques shown in this chapter, define a complete query application for the books database. Provide the following predefined queries: a) Select all authors from the Authors table. b)...
-
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...
-
In each case: i. Sketch the two curves on the same axes ii. State the number of points of intersection iii. Write down a suitable equation which would give the x-coordinates of these points. a y = x,...
-
Your factory has been offered a contract to produce a part for a new printer. The contract would last for 3 years and your cash flows from the contract would be $4.84 million per year. Your upfront...
-
The temporary tax difference is due to a $70,000 sale that could be recognized for GAAP purposes in 2021 but it had to be recognized for tax purposes on a prorata basis through 2023 Sheett a....
-
The following are the accounts of United Forward Trading Limited, a company that engages in Shipping and container services for the years ended 31 December 2014 and 215 respectively. Statements of...
-
In order to calculate the cost of capital, it is necessary to accurately assess the capital structure of a firm. Below is information for estimating the cost of capital for JKM Company. Portion of...
-
Summary : Write a summary of what the financial statements indicate about the companys financial health and performance. Purpose : Discuss the accounting process and the resulting financial...
-
Find each resultant vector R. Give R in standardposition. 425 km 365 km
-
Three forces with magnitudes of 70pounds, 40 pounds, and 60 pounds act on an object at angles of 30, 45, and 135, respectively, with the positive x-axis. Find the direction and magnitude of the...
-
If the bandwidth of the channel is 5 Kbps, how long does it take to send a frame of 100,000 bits out of this device?
-
The light of the sun takes approximately eight minutes to reach the earth. What is the distance between the sun and the earth?
-
List three techniques of digital-to-digital conversion.
-
6. Given the following pseudocode, what will be the final output if m-24 and n=3? r+mn while r=0 do m-n n-r r-men return n
-
Compile the following: #include using namespace std; int num; int& test(); int main() { } test() = 5; cout < < num: return 0; int& test() 5 { return num; }
-
The code of a program as follows. #include #include int main() { int i; for (i=0; i <4; i++) { fork(); } return 0; } Including itself, how many processes are created by the program shown above?
Study smarter with the SolutionInn App