Week 3 Discussion Forum

How efficient is insertion sort?

How efficient is insertion sort?

by Tawhid Ahmed Komol 192-15-2861 -
Number of replies: 0

Insertion sort has worst-case performance of O (n^2), best-case performance of O(n), and average case of O(n^2).

Best case is an already sorted array. Each iteration compares the first element to the right-most element of the sorted sub-array.

Worst case is reverse sorted array, every comparison the inner loop will go over the whole sub-array.

Average case is O (n^2), meaning that it is not a very useful sorting algorithm for a general case, however, it is faster than quicksort on small inputs or when data is nearly sorted. Therefore, it is efficient on these inputs and should be used.


105 words