Saturday, 16 July 2011

Selection sort.

Algorithm


  1. Find the minimum value in the list
  2. Swap it with the value in the first position
  3. Repeat the steps above for the remainder of the list (starting at the second position and advancing each time).
Example:


Consider the array list 64,25,12,22,11. 
Step 1: Min Value is 11.
                        64 25 12 22 11
            Move it to the first position in the array.
Step 2: Min Value in the rest of the array is 12.
                        11 25 12 22 64
            Move it to the second position in the array.
Step 3:Min value in the rest of the array is 22.
                        11 12 25 22 64
             Move it to the third position in the array.
Step 4:Min value in the rest of the array is 25.
           11 12 22 25 64
            Its already in the sorted position.
Step 5: It executes one more time.11 12 22 25 64 
            



            

No comments:

Post a Comment