Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
hard

Merge Sort Algorithm Trace

Mark
< Prev
Next >

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]

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|