Insertion Sort Stepper
Insertion sort builds a sorted region one element at a time. At each step it removes the next element, shifts larger values to the right, and inserts the saved element into the correct gap. Use the controls to follow the algorithm line-by-line and watch the array update in real time.
Pseudocode
- for i ← 1 to length(A) - 1
- key ← A[i]
- j ← i - 1
- while j ≥ 0 and A[j] > key
- A[j + 1] ← A[j]
- j ← j - 1
- A[j + 1] ← key
Array Animation
Press play to begin the demonstration.