Unit 4 · Data Collections
Sorting and Efficiency
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What sorting and efficiency covers
Selection sort finds the smallest remaining element and swaps it into place, so after k passes the first k positions are finalized. Insertion sort grows a sorted prefix by shifting each new element left into position, so after k passes the first k + 1 elements are sorted relative to each other but may still move. Merge sort recursively splits the array, sorts the halves, and merges them, which makes it substantially faster on large inputs.
Where students lose points
Students confuse which prefix is finished: selection sort finalizes its prefix, insertion sort does not. Tracing the array after a specific pass is where most points are lost, usually by performing a full sort mentally and reporting the final array instead of the intermediate state.
How it shows up on the AP exam
Unit 4 material tested through "what does the array look like after pass 2" questions. Knowing the per-pass behavior of each algorithm is worth more on the exam than being able to write the sort from scratch.
For practice use only.
Sorting and Efficiency MCQ Practice
AP CSA sorting and efficiency practice: selection and insertion sort passes, array state after each pass, merge sort behavior, and comparison counts.
Answered 0 of 15
Choose one answer.
The array below is sorted into increasing order by selection sort. What does it hold after the first pass?
public static void selectionPass(int[] values, int start)
{
int least = start;
for (int index = start + 1; index < values.length; index++)
{
if (values[index] < values[least])
{
least = index;
}
}
int saved = values[start];
values[start] = values[least];
values[least] = saved;
}
int[] a = {5, 2, 8, 1};
selectionPass(a, 0);