Procedure Selectionsort (A, n)

The above Procedure Subalgorithm sorts the given element of an array ‘A’ of ‘n’ number of elements in an ascending order. The smallest element that is located in particular pass is denoted by variable ‘S’. The variable ‘p’ denotes the index of a pass and position of the first element which is to be examined during a particular pass.


Step 1 loop, repeated (n – 1) times

Repeat through step 3 for p® 1, 2, 3 ...... n – 1.

set S¬p

Step 2 element with smallest value is obtained in every pass

Repeat step 2 for i¬p + 1, p + 2 ..... n

if (A[S] > A[i]) then

set S¬i

End of step 2 loop

Step 3 Exchanging the values

if ( S¹p) then

set A[p] «A[S]

End of step 1 loop

Step 4Finish