RosettaCodeData/Task/Sorting-algorithms-Selectio.../00DESCRIPTION

22 lines
771 B
Plaintext

{{Sorting Algorithm}}
;Task:
Sort an [[array]] (or list) of elements using the Selection sort algorithm.
It works as follows:
First find the smallest element in the array and exchange it with the element in the first position, then find the second smallest element and exchange it with the element in the second position, and continue in this way until the entire array is sorted.
Its asymptotic complexity is &nbsp; <big> [[O]](n<sup>2</sup>) </big> &nbsp; making it inefficient on large arrays.
Its primary purpose is for when writing data is very expensive (slow) when compared to reading, eg. writing to flash memory or EEPROM.
No other sorting algorithm has less data movement.
;Reference:
* Wikipedia: &nbsp; [[wp:Selection_sort|Selection sort]]
<br><br>