What is the number of swaps required to sort elements using selection sort, in the worst case?
View worked solution
Answer: A
In Selection Sort, the algorithm divides the array into a sorted and an unsorted region. In each of the passes, it finds the minimum element from the unsorted region and swaps it with the element at the beginning of the unsorted region.
Key points regarding the complexity of Selection Sort:
- Comparisons: To find the minimum element in each pass, we perform comparisons. The total number of comparisons is always:
- Swaps: In each of the passes, at most one swap is performed to place the minimum element in its correct position.
Thus, even in the worst case, the total number of swaps is at most , which is .
Therefore, the correct option is (A).
Free practice · Your answers on this page are not saved.
