If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were
Question:
Transcribed Image Text:
/** Sort the subarray S[a.b] inclusive. */ private static
/** Sort the subarray S[a.b] inclusive. */ private static void quickSortInPlace(K[] S, Comparator comp, int a, int b) { 3 // subarray is trivially sorted if (a >= b) return; int left = a; 4 5 int right = b-1; K pivot = S[b]; K temp; while (left <= right) { // scan until reaching value equal or larger than pivot (or right marker) while (left <= right && comp.compare(S[left], pivot) < 0) left++; // scan until reaching value equal or smaller than pivot (or left marker) while (left <= right && comp.compare(S[right], pivot) > 0) right--; if (left <= right) { // so swap values and shrink range temp = S[left]; S[left] = S[right]; S[right] = temp; left++; right--; %3D // temp object used for swapping 10 11 12 13 // indices did not strictly cross 14 15 16 17 18 } // put pivot into its final place (currently marked by left index) temp = S[left]; S[left] = S[b]; S[b] = temp; // make recursive calls quickSortInPlace(S, comp, a, left – 1); quickSortInPlace(S, comp, left + 1, b); 19 20 21 22 23 24 25
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (8 reviews)
Within the loop just after swapping two elements left is incremented and right is decremented ...View the full answer
Answered By
Saurabh Kumar
I just love sharing my shortcuts and techniques with students to approach math problems. It gives me immense satisfaction when they are happy with my solution.
0.00
0 Reviews
10+ Question Solved
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Question Posted:
Students also viewed these Computer science questions
-
Our implementation of the treeSearch utility, from Code Fragment 11.3, relies on recursion. For a large unbalanced tree, it is possible that Javas call stack will reach its limit due to the recursive...
-
In our implementation of the scale function (page 25), the body of the loop executes the command data[j] *= factor. We have discussed that numeric types are immutable, and that use of the *= operator...
-
The performance of a snooping cache-coherent multiprocessor depends on many detailed implementation issues that determine how quickly a cache responds with data in an exclusive or M state block. In...
-
For this project, you must select an employer organization and research the organizations employee benefits package (plan). After you research the organizations employee benefits package, collect...
-
The following events occurred during 2018 for various audit clients of your firm. Consider each event to be independent and the effect of each event to be material. 1. A manufacturing company...
-
Regarding the two statements about discount rate estimates, Chin is A. Correct with respect to adding the small stock premium and correct with respect to the weighted average cost of capital. B....
-
Regional Support for Same Sex Marriage The website http://www.pewresearch.org/ fact-tank/2014/10/15/gay - marriage - arrives - in -the - south-where-the-public-is-less-enthused shows the changing...
-
Waterways Tours uses the units-of-activity method in depreciating its tour boats. One boat was purchased on January 1, 2006, at a cost of $148,000. Over its four-year useful life, the boat is...
-
How does the implementation of Lean Management methodologies foster organizational agility and enhance operational efficiency in complex business ecosystems ?
-
Following is the current asset section from the Ralph Lauren Corporation balance sheet: The 2018 allowance consists of $202.5 for returns and $19.7 for uncollectible accounts. The amounts tor 2017...
-
If the conditional at line 14 of our quickSortInPlace implementation of Code Fragment 12.6 were changed to use condition left < right, instead of condition left /** Sort the subarray S[a.b]...
-
Suppose the method quickSortInPlace is executed on a sequence with duplicate elements. Prove that the algorithm still correctly sorts the input sequence. What happens in the partition step when there...
-
Briefly describe the international monetary systems implemented under the Bretton Woods, Smithsonian, and Jamaica Agreements.
-
Having ARP table entries time out after 1015 minutes is an attempt at a reasonable compromise. Describe the problems that can occur if the timeout value is too small or too large.
-
Consider a router that is managing three flows, on which packets of constant size arrive at the following wall clock times: All three flows share the same outbound link, on which the router can...
-
Consider the virtual circuit switches in Figure 3.45. Table 3.17 lists, for each switch, what port, {VCI} (or {VCI, interface}) pairs are connected to what other. Connections are bidirectional. List...
-
Prepare a report or exhibit showing how statistics are used in educational testing.
-
XDR is used to encode/decode the header for the SunRPC protocol illustrated by Figure 5.18. The XDR version is determined by the RPCVersion field. What potential difficulty does this present? Would...
-
In an experimental design, the ____ variable is manipulated or controlled by the experimenter.
-
You continue to work in the corporate office for a nationwide convenience store franchise that operates nearly 10,000 stores. The per- store daily customer count (i.e., the mean number of customers...
-
Give efficient algorithms for the operations of dividing a -bit integer by a shorter integer and of taking the remainder of a -bit integer when divided by a shorter integer. Your algorithms should...
-
Show that the gcd operator is associative. That is, prove that for all integers a, b, and c, gcd (a, gcd (b, c)) = gcd (gcd (a, b), c),
-
Prove that n 1 , n 2 , n 3 , and n 4 are pairwise relatively prime if and only if gcd(n 1 n 2 , n 3 n 4 ) = gcd (n 1 n 3 , n 2 n 4 ) = 1. More generally, show that n 1 , n 2 , . . . ,n k are pairwise...
-
Ramirez Company installs a computerized manufacturing machine in its factory at the beginning of the year at a cost of $45,300. The machine's useful life is estimated at 10 years, or 403,000 units of...
-
14. (3 points) Write a program that ask the user for 1. their first name and 2. their last name, Enter first name: Matt Enter last name: Priem Hello Matt Priem! and then outputs a greeting similar to...
-
Given a sorted array 2, 5, 8, 12, 16, 18, 22, 25, 29, 32 and the following interpolation search algorithm. Show the steps of the algorithm when 25 is searched. Also, when 26 is searched. array a,...
Study smarter with the SolutionInn App