In: Computer Science
After three passes through the outer loop of a sorting algorithm, an array changes from
43 | 16 | 48 | 37 | 81 | 54 | 71 | 29 |
to
16 | 29 | 37 | 48 | 81 | 54 | 71 | 43 |
What sorting algorithm is being used to sort the array?
A. |
Selection sort |
|
B. |
Bubble sort |
|
C. |
Insertion sort |
A) Selection sort
Original list is [43, 16, 48, 37, 81, 54, 71, 29]
Iteration: 1
> Replace element 43 with minimum number of
remaining list [43, 16, 48, 37, 81, 54, 71, 29]
> Minimum element found is 16. so, swap it with
element at index 0 which is 43
> List after iteration 1 is [16, 43, 48, 37, 81,
54, 71, 29]
Iteration: 2
> Replace element 43 with minimum number of
remaining list [43, 48, 37, 81, 54, 71, 29]
> Minimum element found is 29. so, swap it with
element at index 1 which is 43
> List after iteration 2 is [16, 29, 48, 37, 81,
54, 71, 43]
Iteration: 3
> Replace element 48 with minimum number of
remaining list [48, 37, 81, 54, 71, 43]
> Minimum element found is 37. so, swap it with
element at index 2 which is 48
> List after iteration 3 is [16, 29, 37, 48, 81,
54, 71, 43]