In: Computer Science
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting
the array into ascending order.
Initial array: 5 7 4 9 8 5 6 3
ANSWER (Hint there are 8 lines, Show Array after each selection and swap):
Initial array: 5 7 4 9 8 5 6 3
Iteration: 1
Find the minimum element in the array[0..8]
Minimum is 3, swap with the 0 index
Updated array : 3 7 4 9 8 5 6 5
Iteration: 2
Find the minimum element in the array[1..8]
Minimum is 4, swap with the 1 index
Updated array : 3 4 7 9 8 5 6 5
Iteration: 3
Find the minimum element in the array[2..8]
Minimum is 5, swap with the 2 index
Updated array : 3 4 5 9 8 7 6 5
Iteration: 4
Find the minimum element in the array[3..8]
Minimum is 5, swap with the 3 index
Updated array : 3 4 5 5 8 7 6 9
Iteration: 5
Find the minimum element in the array[4..8]
Minimum is 6, swap with the 4 index
Updated array : 3 4 5 5 6 7 8 9
Iteration: 6
Find the minimum element in the array[4..8]
Minimum is 7, swap with the 5 index, NO CHANGE
Updated array : 3 4 5 5 6 7 8 9
Iteration: 7
Find the minimum element in the array[4..8]
Minimum is 8, swap with the 6 index, NO CHANGE
Updated array : 3 4 5 5 6 7 8 9
Iteration: 8
Find the minimum element in the array[4..8]
Minimum is 9, swap with the 7 index, NO CHANGE
Updated array : 3 4 5 5 6 7 8 9
Finally, Sorted array will become 3 4 5 5 6 7 8 9