Insertion Sort
Last updated
Was this helpful?
Last updated
Was this helpful?
As one of typical Adaptive Sort, insertion sort performs marvelously on list that is partially sorted and it is a great choice for combination with various prevalent sorting algorithms such as and .
The fundamental idea is described as: in each iteration of processing the unsorted array (beginning from the original array), remove the first element (𝕊) of the unsorted part; in an ascending order of sorted part, check the value of 𝕊 against each element of sorted part and insert it into the appropriate location that smaller sorted elements in its left and larger elements in its right.
Note: if using a dynamic structure to store entries such as , you would eliminate multiple times of swapping and only one entry insertion is required for each iteration.
is a stable and adaptive sort scheme and a well-formed algorithm in many technical systems. It normally requires Ο(n2) compares and swaps but in the best case when the given inputs are nearly sorted, it could only require Ο(n) compares and swaps.
Despite of high efficiency of Insertion Sort in almost sorted list, it consumes many swaps to sort the entire list. improves upon the deficiencies of .