In: Computer Science
index |
1 |
2 |
3 |
4 |
5 |
6 |
data |
11 |
10 |
21 |
3 |
7 |
5 |
Selection sort Original list is [11, 10, 21, 3, 7, 5] Iteration: 1 > Replace element 11 with minimum number of remaining list [11, 10, 21, 3, 7, 5] > Minimum element found is 3. so, swap it with element at index 0 which is 11 > List after iteration 1 is [3, 10, 21, 11, 7, 5] Iteration: 2 > Replace element 10 with minimum number of remaining list [10, 21, 11, 7, 5] > Minimum element found is 5. so, swap it with element at index 1 which is 10 > List after iteration 2 is [3, 5, 21, 11, 7, 10] Iteration: 3 > Replace element 21 with minimum number of remaining list [21, 11, 7, 10] > Minimum element found is 7. so, swap it with element at index 2 which is 21 > List after iteration 3 is [3, 5, 7, 11, 21, 10] Iteration: 4 > Replace element 11 with minimum number of remaining list [11, 21, 10] > Minimum element found is 10. so, swap it with element at index 3 which is 11 > List after iteration 4 is [3, 5, 7, 10, 21, 11] Iteration: 5 > Replace element 21 with minimum number of remaining list [21, 11] > Minimum element found is 11. so, swap it with element at index 4 which is 21 > List after iteration 5 is [3, 5, 7, 10, 11, 21] Sorted list is [3, 5, 7, 10, 11, 21]