original QuickSort implementation. Hoare’s algorithm keeps two indices and iterates through the loop from the front and the back simultaneously towards the center. If it finds a pair of elements out of place it swaps them. It terminates when the index keeping track of the low side is greater than or equal to the index keeping track of the
Please do not change any of the method signatures in either class. Implement the methods described below.
public static int partitionHoare(int[] arr, int low, int high)
Hoare’s partition
paritionHoare(arr,p,r)
pivot = arr[p]
i = p-1
j = r+1
while true:
repeat j = j-1 until arr[j]≤pivot
repeat i = i+1 until arr[i]≥pivot
if i<j
swap arr[i] and arr[j] else
return j
What sort of input arrays will enable Hoare’s algorithm to still create relatively equal size partitions whereas Lumoto’s algorithm will create unequal partitions? Write your answer in the location specified in Partition.java.
Below is Method signature class:
package sorting;
import java.util.Arrays;
public class Partition {
/***********ANSWER QUESTION HERE*****************/
/*
* What sort of input arrays will enable Hoare’s algorithm to still create relatively
* equal size partitions whereas Lomuto’s algorithm will create unequal partitions?
*/
public static int partitionHoare(int[] arr,int low, int high) {
return 0;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images