Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Selection sort in C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 74
    Comment on it

    Selection sort as the name suggests, first select the least element from the entire list in every iteration and swap it with the position for which iteration is being performed.

     

    In the given figure it is seen that in the first iteration the first and second element is compared the smaller value is placed at the first position , after this in the second and third element is compared and so on .

     

    How selection sort algorithm works in programming?

     

    Algorithm for Selection Sort

     

    Step 1  Set MIN to location 0
    Step 2  Search the minimum element in the list
    Step 3  Swap with value at location MIN
    Step 4  Increment MIN to point to next element
    Step 5  Repeat until list is sorted

     

    It is clearly seen from the algorithm that the location is compared one by one in every iteration and swapping is been done.

     

    procedure selection sort 
       list  : array of items
       n     : size of list
    
       for i = 1 to n - 1
       /* set current element as minimum*/
          min = i    
      
          /* check the element to be minimum */
    
          for j = i+1 to n 
             if list[j] < list[min] then
                min = j;
             end if
          end for
    
          /* swap the minimum element with the current element*/
          if indexMin != i  then
             swap list[min] and list[i]
          end if
    
       end for
    	
    end procedure

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: