***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Wednesday 4 December 2019

Selection Sort




















Performance of selection sort:

The worst case for selection sort occurs when the first item in the list is the largest, and the rest of the list is in order. In this case, we perform one swap on each pass through the algorithm, so the number of swaps is N. The number of comparisons is the same as in the best case, O(2).

The average case requires the same number of comparisons, O(2), and roughly N/2 swaps. Thus, the number of swaps in the average case is O().

In summary, we say that selection sort is O() in swaps and O(2) in comparisons.

No comments:

Post a Comment