Question: If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were changed to use condition left < right, instead
If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were changed to use condition left < right, instead of condition left <= right, there would be a flaw. Explain the flaw and give a specific input sequence on which such an implementation fails.
![/** Sort the subarray S[a.b] inclusive. */ private static <K> void quickSortInPlace(K[] S, Comparator<K> comp, int a, in](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1544/6/2/5/3785c111ce2684f01544607938880.jpg)
/** 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
Step by Step Solution
3.41 Rating (167 Votes )
There are 3 Steps involved in it
Within the loop just after swapping two elements left is incremented and right is decremented ... View full answer
Get step-by-step solutions from verified subject matter experts
