Copyright © Philip M. Parker, INSEAD. Terms of Use.

INSERTION SORT

Specialty Definition: INSERTION SORT

DomainDefinition

Computing

Insertion sort A sorting algorithm that inserts each item in the proper place into an initially empty list by comparing it with each item in the list until it finds the new element's successor or the end of the list. Compare bubble sort. (1997-02-12). Source: The Free On-line Dictionary of Computing.

Math

Sort by repeatedly taking the next item and inserting it into the final data structure in its proper order with respect to items already inserted. Run time is O(n2) because of moves. (references)

Source: compiled by the editor from various references; see credits.

Top     

Specialty Definition: Insertion sort

(From Wikipedia, the free Encyclopedia)

Insertion sort is a simple sort algorithm where the result is built up one entry at a time.

In abstract terms, each iteration of an insertion sort removes an element from the input data, inserting it at the correct position in the already sorted list, until no elements are left in the input. The choice of which element to remove from the input is arbitrary.

Sorting is done in-place. The result array after k iterations contains the first k entries of the input array and is sorted. In each step, the first remaining entry of the input is removed, inserted into the result at the right position, thus extending the result:

 +------ result ------+------ input ------+
 |   <= x   |   > x   | x |      ...      |
 +--------------------+-------------------+
becomes:
 +-------- result --------+---- input ----+
 |   <= x   | x |   > x   |      ...      |
 +------------------------+---------------+
with each element > x copied to the right as it is compared against x.

The algorithm can be described as:

  1. Start with the result being the first element of the input.
  2. Loop over the input until it is empty, "removing" the first remaining (leftmost) element.
  3. Compare the removed element against the current result, starting from the highest (rightmost) element, and working left towards the lowest element.
  4. If the removed input element is lower than the current result element, copy that value into the following element to make room for the new element below, and repeat with the next lowest result element.
  5. Otherwise, the new element is in the correct location; save it in the cell left by copying the last examined result up, and start again from (2) with the next input element.

A simple Python implementation of this follows:

def straightinsertionsort(array):
   for removed_index in range(1, len(array)):
       removed_value = array[removed_index]
       insert_index = removed_index
       while insert_index > 0 and array[insert_index - 1] > removed_value:
           array[insert_index] = array[insert_index - 1]
           insert_index = insert_index - 1
       array[insert_index] = removed_value

One coding using a functional programming language such as Haskell might be:

> insert :: Ord a => a -> [a] -> [a]
> insert item []  = [item]
> insert item (h:t) | item <= h = item:h:t
>                   | otherwise = h:(insert item t)

> insertsort :: Ord a => [a] -> [a] > insertsort [] = [] > insertsort (h:t) = insert h (insertsort t)

Insertion sort is very similar to bubble sort. In bubble sort, after k passes through the array, the k largest elements have bubbled to the top. (Or the k smallest elements have bubbled to the bottom, depending on which way you do it.) In insertion sort, after k passes through the array, you have a run of k sorted elements at the bottom of the array. Each pass inserts another element into the sorted run. So with bubble sort, each pass takes less time than the previous one, but with insertion sort, each pass may take more time than the previous one.

In the best case of an already sorted array, this implementation of insertion sort takes O(n) time: in each iteration, the first remaining element of the input is only compared with the last element of the result. It takes O(n2) time in the average and worst cases, which makes it impractical for sorting large numbers of elements. However, insertion sort's inner loop is very fast, which often makes it one of the fastest algorithms for sorting small numbers of elements, typically less than 10 or so.

D.L. Shell made an improvement to the algorithm, called Shellsort, that compares elements separated by a distance that decreases on each pass. Quicksort works by dividing the array to be sorted into smaller runs to be sorted separately; highly optimized implementations of Quicksort often use insertion sort to sort these runs once they get small enough.

Source: adapted by the editor from Wikipedia, the free encyclopedia under a copyleft GNU Free Documentation License (GFDL) from the article "Insertion sort."

Top     

Crosswords: INSERTION SORT

Specialty definitions using "INSERTION SORT": binary insertion sortdiminishing increment sortgarbageabetical order. (references)

Top     

Frequency of Internet Keywords: INSERTION SORT

The following statistics estimate the number of searches per day across the major English-language search engines as identified by various trade publications. Hyperlinks lead to commercial use of the expression at Amazon.com.
 
ExpressionFrequency
per Day

insertion sort

22

algorithm insertion sort

3

c++ insertion sort

3

insertion insertion sort sort

2
Source: compiled by the editor from various references; see credits.

Top     

Anagrams: INSERTION SORT

Scrabble® Enable2K-Verified Anagrams

Words within the letters "e-i-i-n-n-o-o-r-r-s-s-t-t"

-3 letters: insertions, internists, ironstones, nonrioters, nonstories, serotonins, sonorities, sororities, sortitions, torosities, tretinoins.

-4 letters: insertion, insistent, interiors, internist, ironstone, nonrioter, serotonin, snootiest, sortition, tenorists, tinstones, tortoises, tretinoin.

-5 letters: erosions, inosites, insister, interior, intoners, introits, introrse, ironists, ironness, isotones, nitrites, noisiest, notornes, notornis, oestrins, osteitis, resistor, risottos, roisters, roosters, rootiest, sinister, snootier, snorters, snottier, sootiest, sorriest.

 Words containing the letters "e-i-i-n-n-o-o-r-r-s-s-t-t"
 

+4 letters: contradictoriness, reconstructionism, reconstructionist.

 

+5 letters: reconstructionisms, reconstructionists.

Source: compiled by the editor from various references; see credits.

SCRABBLE® is a registered trademark. All intellectual property rights in and to the game are owned in the U.S.A and Canada by Hasbro Inc., and throughout the rest of the world by J.W. Spear & Sons Limited of Maidenhead, Berkshire, England, a subsidiary of Mattel Inc. Mattel and Spear are not affiliated with Hasbro.

Top     

Alternative Orthography: INSERTION SORT


Hexadecimal (or equivalents, 770AD-1900s) (references)

49 4E 53 45 52 54 49 4F 4E      53 4F 52 54

Leonardo da Vinci (1452-1519; backwards) (references)

    

Binary Code (1918-1938, probably earlier) (references)

01001001 01001110 01010011 01000101 01010010 01010100 01001001 01001111 01001110 00100000 01010011 01001111 01010010 01010100

HTML Code (1990) (references)

&#73 &#78 &#83 &#69 &#82 &#84 &#73 &#79 &#78 &#32 &#83 &#79 &#82 &#84

ISO 10646 (1991-1993) (references)

0049 004E 0053 0045 0052 0054 0049 004F 004E      0053 004F 0052 0054

Encryption (beginner's substitution cypher): (references)

434853395254434948253495254

Top     



INDEX

1. Crosswords
2. Expressions: Internet
3. Anagrams
4. Orthography
5. Bibliography


  

Copyright © Philip M. Parker, INSEAD. Terms of Use.