more complicated algorithms in certain situations selection sort is generally used for sorting files with very large objects (recordsand small keys technique consider an array arr with elements selection sort works as followsfirst find the smallest value in the array and place it in the first position thenfind the second smallest value in the array and place it in the second position repeat this procedure until the entire array is sorted thereforein pass find the position pos of the smallest value in the array and then swap arr[posand arr[ thusarr[ is sorted in pass find the position pos of the smallest value in sub-array of - elements swap arr[poswith arr[ nowarr[ and arr[ is sorted in pass - find the position pos of the smaller of the elements arr[ - and arr[ - swap arr[posand arr[ - so that arr[ ]arr[ ]arr[ - is sorted example sort the array given below using selection sort pass pos arr[ arr[ arr[ arr[ arr[ arr[ arr[ arr[ the algorithm for selection sort is shown in fig in the algorithmduring the kth passwe need to find the position pos of the smallest elements from arr[ ]arr[ + ]arr[nto find the smallest elementwe use variable small to hold the smallest value in the sub-array ranging from arr[kto arr[nthenswap arr[kwith arr[posthis procedure is repeated until all the elements in the array are sorted smallest (arrknposselection sort(arrnstep [initializeset small arr[kstep [initializeset pos step repeat for + to - if small arr[jset small arr[jset pos [end of if[end of loopstep return pos step repeat steps and for to - step call smallest(arrknposstep swap [kwith arr[pos[end of loopstep exit figure algorithm for selection sort complexity of selection sort selection sort is sorting algorithm that is independent of the original order of elements in the array in pass selecting the element with the smallest value calls for scanning all elements