Selection Sort

Selection Sort :

The idea of selection sort is rather simple. In this we repeatedly find the largest and smallest value in  array and place it at its final position as required for ascending or descending order. It is less efficient than insertion sort and has n2 complexity for all three cases.It is also not  much efficient for larger amount of data.

Worst Case:O(n2)

Average Case:O(n2)

Best Case:O(n2)

ALGORITHM:

    • Input array as a[]
    • for i=0 to i<n-1
      for j=i+1 to n
      find the smallest in between j to (n-1)th index and compare and swap it with i th index.
    • Print the sorted array

e.g, To sort  5,3,2,0


C SOURCE CODE:

Leave a Reply

Your email address will not be published. Required fields are marked *