Merge Sort Algorithm Trace
Consider the following mergeSort method. The merge method, which is not shown, is assumed to correctly merge two sorted subarrays.
public static void mergeSort(int[] arr, int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;
mergeSort(arr, left, mid);
mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
When this method is executed on the array [9, 1, 4, 2], what are the contents of the array immediately after the second merge operation completes?
A
[1, 9, 4, 2]
B
[9, 1, 2, 4]
C
[1, 2, 4, 9]
D
[1, 9, 2, 4]
Question Leaderboard
Not enough data yet to show leaderboard.
