Jump to content

Insertion Sort

From Encyclopedia of Algorithms
Revision as of 14:18, 4 August 2026 by Aitzaz (talk | contribs) (Introductory page.)

This article is a stub. It might be missing pseudocode, complexity analysis, or a correctness sketch. It might need some other information which is incomplete perhaps.

Insertion sort
Insertion-Sort(A)
  1. for i = 2 to A.length
  2. key = A[i]
  3. j = i - 1
  4. while j > 0 and A[j] > key
  5. A[j + 1] = A[j]
  6. j = j - 1
  7. A[j + 1] = key

Insertion sort is an algorithm for Sorting Problem, arranging an un-ordered list to an ordered list. We assume the first element of the un-ordered list to be ordered such that:

  • Sub-array: $[1, j-1]$ is sorted.
  • Key: $[j]$ is the key we concern with.
  • Sub-array: $[j+1, A.length]$ is concerned.

As the insertion sort operates, it is guaranteed that $[1, j-1]$ is sorted.