Which one of the following is the tightest upper bound that represents the number of swaps required to sort numbers using selection sort?
View worked solution
Answer: B
In Selection Sort, the algorithm divides the array into a sorted and an unsorted region. In each of the passes, it performs the following steps:
- Finds the minimum (or maximum) element in the unsorted subarray.
- Swaps this minimum element with the first element of the unsorted subarray.
Since exactly one swap is performed per pass, the total number of swaps required to sort numbers is at most .
Therefore, the tightest upper bound for the number of swaps is .
Comparison of Options:
- Option A (): Too small; we need up to swaps in the worst case.
- Option B (): Correct and the tightest upper bound.
- Option C () and Option D (): While these are valid upper bounds, they are not the tightest upper bounds for the number of swaps (though is the tightest upper bound for the number of comparisons).
Free practice · Your answers on this page are not saved.
