What is the number of swaps required to sort $n$ elements using selection sort, in the worst case?
$\Theta(n)$
$\Theta(n \log n)$
$\Theta(n^2)$
$\Theta(n^2 \log n)$
Selection sort:
The answer is A.
In worst case, we have $1$ swap in each loop except the last one and hence $n-1$ swaps at max for $1$ to $n$. Therefore the worst case number of swaps is $\Theta(n)$
@reena ma'am, it depends on implementation, but in its basic form, even in best case selection sort requires 1 swap in each pass. https://stackoverflow.com/questions/26688765/what-are-the-number-of-swaps-required-in-selection-sort-for-each-case
option a
64.3k questions
77.9k answers
244k comments
80.0k users