1. INSERTION-SORT(A)
  2. 1for i ← 1 to n − 1 do
  3. 2key ← A[i]
  4. 3j ← i − 1
  5. 4while j ≥ 0 and A[j] > key do ▷ > and not ≥ keeps the sort stable
  6. 5A[j + 1] ← A[j]
  7. 6j ← j − 1
  8. 7A[j + 1] ← key
0 / 0
Use your own input

Type the input as JSON, in the same form as a preset.

Open the full player

Insertion sort on Algorithm