The main advantage of insert sort is that it's online algorithm. You don't have to have all the values at start. This could be useful, when dealing with data coming from network, or some sensor.
I have a feeling, that this would be faster than other conventional n log(n)
algorithms. Because the complexity would be n*(n log(n))
e.g. reading/storing each value from stream (O(n)
) and then sorting all the values (O(n log(n))
) resulting in O(n^2 log(n))
On the contrary using Insert Sort needs O(n)
for reading values from the stream and O(n)
to put the value to the correct place, thus it's O(n^2)
only. Other advantage is, that you don't need buffers for storing values, you sort them in the final destination.