Which of the following sorting algorithm required the least swap to so...
Selection sort is a sorting algorithm in which the smallest element always move to the extreme left corner of the list,
Point to remember - If the array is sorted in ascending order, even though the selection sort takes the same number of comparisons, as of unsorted array. The maximum number of swaps and comparisons are required when the array is sorted in descending order.
Now, applying selection sort on L1- [52,18,16,12,36,26,22]
Minimum element in the list is 12 , So, swap 52 with 12.
After 1st pass - [12,18,16,52,36,26,22] (1 swap)
The minimum element is 16 now, swap 18 with 16.
After 2nd pass - [12,16,18,52,36,26,22] (1 swap)
In the 3rd pass, no change as 18 is in the correct position.
After 3rd pass - [12,16,18,52,36,26,22]
Now, 22 is the minimum element, swap 52 with 22.
After 4th pass - [12,16,18,22,36,26,52] (1 swap)
Minimum element is now 26 , swap 36 , with 26
After 5th pass - [12,16,18,22,26,36,52] (1 swap)
Now, the list is already sorted after the 5th pass, so, a total of 4 swaps are required for the selection sort.
So, option 2 will be the answer.