In: Computer Science
Using the following data set:
100, 50, 20, 70, 200, 30, 130
Apply the selection sort algorithm [Show the first four iterations only]
Selection sort Original list is [100, 50, 20, 70, 200, 30, 130] Iteration: 1 > Replace element 100 with minimum number of remaining list [100, 50, 20, 70, 200, 30, 130] > Minimum element found is 20. so, swap it with element at index 0 which is 100 > List after iteration 1 is [20, 50, 100, 70, 200, 30, 130] Iteration: 2 > Replace element 50 with minimum number of remaining list [50, 100, 70, 200, 30, 130] > Minimum element found is 30. so, swap it with element at index 1 which is 50 > List after iteration 2 is [20, 30, 100, 70, 200, 50, 130] Iteration: 3 > Replace element 100 with minimum number of remaining list [100, 70, 200, 50, 130] > Minimum element found is 50. so, swap it with element at index 2 which is 100 > List after iteration 3 is [20, 30, 50, 70, 200, 100, 130] Iteration: 4 > Replace element 70 with minimum number of remaining list [70, 200, 100, 130] > Minimum element found is 70. so, swap it with element at index 3 which is 70 > List after iteration 4 is [20, 30, 50, 70, 200, 100, 130] Iteration: 5 > Replace element 200 with minimum number of remaining list [200, 100, 130] > Minimum element found is 100. so, swap it with element at index 4 which is 200 > List after iteration 5 is [20, 30, 50, 70, 100, 200, 130] Iteration: 6 > Replace element 200 with minimum number of remaining list [200, 130] > Minimum element found is 130. so, swap it with element at index 5 which is 200 > List after iteration 6 is [20, 30, 50, 70, 100, 130, 200] Sorted list is [20, 30, 50, 70, 100, 130, 200]