In: Computer Science
X = [7, 9, 1, 6]
Sort the array in ascending order using the selction sort algorithm.
Write the state of the array after each pass.
Pass1:
Pass2:
Pass3:
X = [7, 9, 1, 6]
Sort the array in ascending order using the selction sort algorithm.
Write the state of the array after each pass.
Pass1:
Pass2:
Pass3:
Pass1: [1, 9, 7, 6] Pass2: [1, 6, 7, 9] Pass3: [1, 6, 7, 9] Explanation: ------------- Selection sort Original list is [7, 9, 1, 6] Iteration: 1 > Replace element 7 with minimum number of remaining list [7, 9, 1, 6] > Minimum element found is 1. so, swap it with element at index 0 which is 7 > List after iteration 1 is [1, 9, 7, 6] Iteration: 2 > Replace element 9 with minimum number of remaining list [9, 7, 6] > Minimum element found is 6. so, swap it with element at index 1 which is 9 > List after iteration 2 is [1, 6, 7, 9] Iteration: 3 > Replace element 7 with minimum number of remaining list [7, 9] > Minimum element found is 7. so, swap it with element at index 2 which is 7 > List after iteration 3 is [1, 6, 7, 9] Sorted list is [1, 6, 7, 9]