what is selection sort:-
In this sorting technique you can sort an array by repeatedly finding the min element and putting this element at the starting of the array.
example:-
you have to sort the array :- 2 32 4 65 3 7 then
step 1:- first we have to find the min in this array which is 2 at put this in the beginning
2 32 4 65 3 7
step 2:- find the min in unsorted array( except first element because first element sorted in in step 1) which is 3 so put in the beginning of unsorted array
2 3 32 4 65 7
step 3:- find the min in unsorted array (which is 4) and put it in the beginning of the unsorted array
2 3 4 32 65 7
step 4:- find the min in unsorted array (which is 7) and put it in the beginning of the unsorted array
2 3 4 7 32 65
step 4:- find the min in unsorted array (which is 32) and put it in the beginning of the unsorted array
2 3 4 7 32 65
This is the sorted array.
Note:- the number of step required for the sorting is equal to n-1 where n is the size of the array.
Code:-
Output:-
0 Comments