0% found this document useful (0 votes)
46 views5 pages

Selection Sort

Selection sort is an algorithm that sorts an array by repeatedly finding the minimum element from the unsorted portion and moving it to the beginning of the sorted portion. It maintains two subarrays: a sorted subarray and an unsorted subarray. In each iteration, it selects the smallest item from the unsorted subarray and inserts it into the sorted subarray. The algorithm scans the entire unsorted subarray to find the minimum element in each pass.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views5 pages

Selection Sort

Selection sort is an algorithm that sorts an array by repeatedly finding the minimum element from the unsorted portion and moving it to the beginning of the sorted portion. It maintains two subarrays: a sorted subarray and an unsorted subarray. In each iteration, it selects the smallest item from the unsorted subarray and inserts it into the sorted subarray. The algorithm scans the entire unsorted subarray to find the minimum element in each pass.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Selection Sort

Sorting Algorithm
What is Selection Sort?
• The selection sort algorithm sorts an array by repeatedly
finding the minimum element (considering ascending
order) from unsorted part and putting it at the beginning.
The algorithm maintains two subarrays in a given array.
• 1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
• In every iteration of selection sort, the minimum element
(considering ascending order) from the unsorted
subarray is picked and moved to the sorted subarray.
-Sorted

-current item

-current minimum

• During each iteration we’ll select the smallest


item from the unsorted partition and move it to
the sorted partition.
10 5 2 1 3 6 4 7 9 8
Sample Pseudocode For(j=0; j < n; j++){
int iMin = j;
for( i = j+1; i < n; i++){
if(a[i] < a[iMin]){
iMin = i; }
}
temp = a[iMin];
a[iMin] = a[j];
a[j] = temp;
}

You might also like