Sorting visualizer

Insertion Sort

Insert each value into an already sorted prefix.

Example Array
[42, 17, 8, 33, 25, 11, 60, 29]

Visualization

Ready
ComparingMoving / writingPivotSorted

Insertion Sort is ready to grow a sorted prefix.

Metrics

Comparisons0
Writes0
Progress0%
Time taken0.0s

Pseudocode

  1. for i from 1 to n - 1
  2. key = arr[i]
  3. j = i - 1
  4. while j >= 0 and arr[j] > key
  5. arr[j + 1] = arr[j]
  6. j = j - 1
  7. arr[j + 1] = key
  8. return arr

About Insertion Sort

Insertion Sort grows a sorted section one value at a time. It shifts larger values to the right until the current value can be inserted in the correct position.

Sorted Output

[ 8, 11, 17, 25, 29, 33, 42, 60 ]

Complete the visualization to reach this output.

Complexity Overview

Best CaseO(n)
Average CaseO(n²)
Worst CaseO(n²)
SpaceO(1)
StableYes