Selection Sort Algorithm:-
Like Bubble sort algorithm, Selection sort is also used to sort the given array elements but in Selection sort the smallest number from given array elements reaches its correct position or index in first pass. n-1 comparisons are made in the first pass, n-2 in second pass and so on until the given array is unsorted.
Total no. of comparisons =
(n-1) + (n-2) + ... + 4 + 3 + 2 + 1 = n(n-1)/2
Number of passes <= n - 1
where n is the no. of array elements.
Complexity of Selection sort is also as same as of the Bubble sort, O(n^2).
Example:-
No comments:
Post a Comment