Quicksort Partition Method Execution
Given the partition method below, what is the resulting state of the array {9, 3, 4, 8, 2} after the method is called with low = 0 and high = 4?
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
{2, 8, 4, 3, 9}
B
{2, 3, 4, 8, 9}
C
{3, 2, 4, 8, 9}
D
{9, 3, 4, 8, 2}
Question Leaderboard
Not enough data yet to show leaderboard.
