DEV Community

Cover image for Insertion Sort Quick Reference

Insertion Sort Quick Reference

edA‑qa mort‑ora‑y on October 01, 2019

Insertion sort is a commonly taught algorithm for sorting a list of items. Though not commonly used, as it's not efficient, it may come up during i...
Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

O(n · log n) is not entirely correct as if you are counting comparisons then yes it's O(n · log n) but if you want to insert an element in the middle of the array you have to shift all the items right by one. Thus it can cost as much as n so the total cost can be:
O(n2)

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

I state that in the Time: Copies section.