Why is Insertion sort better than Quick sort for small list of elements?

user1031752 picture user1031752 · Nov 12, 2011 · Viewed 43.9k times · Source

Isn't Insertion sort O(n^2) > Quicksort O(n log n)...so for a small n, won't the relation be the same?

Answer

Casey Robinson picture Casey Robinson · Nov 12, 2011

Big-O Notation describes the limiting behavior when n is large, also known as asymptotic behavior. This is an approximation. (See http://en.wikipedia.org/wiki/Big_O_notation)

Insertion sort is faster for small n because Quick Sort has extra overhead from the recursive function calls. Insertion sort is also more stable than Quick sort and requires less memory.

This question describes some further benefits of insertion sort. ( Is there ever a good reason to use Insertion Sort? )