Enter an array separated by commas as : 16,15,15,10,1 or just press the hand icon to generate a random array then press enter or Sort button. Sorting will start and you can watch each pass as it gets sorted. When it shows green it means the two of them are being compared when red shows, it means the left number is greater than right number so it needs swapping The blue color means the number is at its correct position and thus sorted it will continue to check other numbers until it reaches end.
Selection sort has been around since the early days of computer programming. It was developed as a simple, intuitive algorithm for sorting data. The concept has been used in various forms across multiple programming languages since the 1960s.
O(n2)
– Regardless of the initial
arrangement.
O(n2)
– Quadratic complexity for average
cases.
O(n2)
– Quadratic complexity for worst
cases.
Space Complexity: O(1)
– It is an in-place sorting algorithm
requiring
a constant amount of additional space.
function selectionSort(arr):
n = length(arr)
for i from 0 to n-1:
minIndex = i
for j from i+1 to n:
if arr[j] < arr[minIndex]:
minIndex = j
/* Swap the found minimum element with the first element */
temp = arr[i]
arr[i] = arr[minIndex]
arr[minIndex] = temp
return arr
Selection sort is a simple algorithm that divides the input list into a sorted and an unsorted
region. Despite its O(n2)
complexity, its simplicity makes it useful for
small
datasets and educational purposes.