<P> which is of complexity O (n 2) (\ displaystyle O (n ^ (2))) in terms of number of comparisons . Each of these scans requires one swap for n − 1 (\ displaystyle n - 1) elements (the final element is already in place). </P> <P> Among simple average - case Θ (n) algorithms, selection sort almost always outperforms bubble sort and gnome sort . Insertion sort is very similar in that after the kth iteration, the first k elements in the array are in sorted order . Insertion sort's advantage is that it only scans as many elements as it needs in order to place the k + 1st element, while selection sort must scan all remaining elements to find the k + 1st element . </P> <P> Simple calculation shows that insertion sort will therefore usually perform about half as many comparisons as selection sort, although it can perform just as many or far fewer depending on the order the array was in prior to sorting . It can be seen as an advantage for some real - time applications that selection sort will perform identically regardless of the order of the array, while insertion sort's running time can vary considerably . However, this is more often an advantage for insertion sort in that it runs much more efficiently if the array is already sorted or "close to sorted ." </P> <P> While selection sort is preferable to insertion sort in terms of number of writes (Θ (n) swaps versus Ο (n) swaps), it almost always far exceeds (and never beats) the number of writes that cycle sort makes, as cycle sort is theoretically optimal in the number of writes . This can be important if writes are significantly more expensive than reads, such as with EEPROM or Flash memory, where every write lessens the lifespan of the memory . </P>

When is selection sort better than insertion sort
find me the text answering this question