Neocortex 🧠

Search

Search IconIcon to open search

Insertion Sort on a Partially Sorted List

Last updated Dec 21, 2021 Edit Source

When you have a partially sorted list, you can change the definition of the Priority Queue you use in Insertion Sort so that the new elements are first added to the end of the queue. This way, the algorithm’s time complexity changes to $O(n+I)$ where $I$ is the number of inversions1 in a list.


  1. A pair of elements in the list that start out in the wong relative order. ↩︎


Interactive Graph