Quicksort Partition Method Execution
After executing partition on the array {9, 3, 4, 8, 2} with low = 0 and high = 4, what is the state of the array?
public class QuickPartition {
public static int partition(int[] arr, int low, int high) {
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] < pivot) {
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}
}
A
{3, 2, 4, 8, 9}
B
{2, 3, 4, 8, 9}
C
{2, 8, 4, 3, 9}
D
{9, 3, 4, 8, 2}
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE