AP Computer Science a · Question of the Day

AP Computer Science a Question of the Day

A fresh daily question to build accuracy, reinforce recall, and turn practice into a steady habit.
Thursday, September 17, 2026

The selection sort algorithm is applied to the array {3, 8, 2, 5, 1, 4}. What is the state of the array immediately after the call to swap elements for the third time?

Keep practicing AP Computer Science a

Question of the Day

Answer today's AP Computer Science a question, reveal the full explanation, then keep the streak going with a new question every day.

The selection sort algorithm is applied to the array {3, 8, 2, 5, 1, 4}. What is the state of the array immediately after the call to swap elements for the third time?

  1. {1, 2, 3, 5, 8, 4} (correct answer)
  2. {1, 2, 8, 5, 3, 4}
  3. {1, 2, 3, 4, 5, 8}
  4. {1, 2, 4, 5, 3, 8}

Explanation: 1st swap (j=0): min is 1, swap with 3 -> {1, 8, 2, 5, 3, 4}. 2nd swap (j=1): min is 2, swap with 8 -> {1, 2, 8, 5, 3, 4}. 3rd swap (j=2): min is 3, swap with 8 -> {1, 2, 3, 5, 8, 4}. This is the state after the third swap completes.