Multiple choice

Which of the following sorting techniques is the most efficient for small, almost sorted data sets?

  1. selection sort

  2. bubble sort

  3. insertion sort

  4. merge sort

  5. heap sort

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Insertion sort provides several advantages such as simple implementation, efficient for (quite) small data sets, more efficient in practice than most other simple quadratic (i.e., O(n2)) algorithms such as selection sort or bubble sort, adaptive, i.e., efficient for data sets that are already substantially sorted: the time complexity is O(nk) when each element in the input is no more than k places away from its sorted position, stable; i.e. does not change the relative order of elements with equal keys, in-place; i.e., only requires a constant amount O(1) of additional memory space,online; i.e., can sort a list as it receives it.