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

/** 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

1 Expert Approved Answer
Step: 1 Unlock

Within the loop just after swapping two elements left is incremented and right is decremented ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!