SESK: Stuff Everyone Should Know · sesk.info/tech-insertion-sort-quadratic
What is the worst-case running time of insertion sort on n items?
O(n²), quadratic: double the items, about four times the work.
- O(n log n)
- O(n²) ✔
- O(log n)
Why: Insertion sort takes each new item and slides it back past every bigger item already sorted. In a reverse-sorted list, item number k moves k places, and adding those up gives about n squared over 2 moves.
Huh, didn't know that: On reverse-sorted input, each new item can move past every item before it.
Insertion sort is how I organize cards in my hand. Slowly, and with a lot of shuffling.
Like this card?
References
Answer: O(n²). Insertion sort takes each new item and slides it back past every bigger item already sorted. In a reverse-sorted list, item number k moves k places, and adding those up gives about n squared over 2 moves.
- MIT 6.006 Introduction to Algorithms, Lecture 3: Sorting ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/resources/mit6_006s20_lec3
insertion sort analysis: ... T(1) = Θ(1), T(n) = T(n − 1) + Θ(n) =⇒ T(n) = Θ(n2)
Checked 2026-10-10.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.