Selection Sort
Selection sort is a simple sorting algorithm. The list is divided into two parts,
The sorted part at the left end and
The unsorted part at the right end
Initially, the sorted part is empty and the unsorted part is the entire list.
The smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. This process continues moving unsorted array boundary by one element to the right. This algorithm is not suitable for large data sets as its average and worst-case complexities are of Ο(n2), where n is the number of items.
Algorithm
SELECTION_SORT(K,N)
Given a vector K of N elements
This procedure rearranges the vector in ascending order using Selection Sort
The variable PASS denotes the pass index and position of the first element in the vector.
The variable MIN_INDEX denotes the position of the smallest element encountered.
The variable I is used to index elements

Selection Sort





Example
Last updated