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, 2, 3, 5, 8, 4} (correct answer)
- {1, 2, 8, 5, 3, 4}
- {1, 2, 3, 4, 5, 8}
- {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.