Skip to content

Files

Latest commit

e7f578c · Apr 28, 2017

History

History
This branch is 6 commits behind Algorithm-archive/Learn-Data_Structure-Algorithm-by-Javascript:master.

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 27, 2017
Apr 28, 2017
Apr 8, 2017

README.md

Insertion Sort

Insertion sort does exactly what you would expect: it inserts each element of the array into its proper position, leaving progressively larger stretches of the array sorted. What this means in practice is that the sort iterates down an array, and the part of the array already covered is in order; then, the current element of the array is inserted into the proper position at the head of the array, and the rest of the elements are moved down, using the space just vacated by the element inserted as the final space.

Insertion Sort

A visualization on Insertion Sort

Insertion sort demonstration

Complexity Analysis

  • Worst Case - О(n2)
  • Average Case - О(n2)
  • Best Case - O(n)

More on this topic