Sort Target
Algorithm
Speed
Normal ~12s · 333 ms/step
Insertion sort(1945)
▶ Try this Source
O(n²) ✓ Stable ✓ In-place
🔧 How it works

Picks up each element from the unsorted boundary and shifts it leftward through the sorted region one position at a time until it lands in its correct position.

🎯 Key property

Degrades to O(n) on nearly-sorted input because very few shifts are needed per element, which is why it is used as the finishing step in advanced hybrids such as Timsort and Introsort once sub-arrays are small.

👁 Watch for
  • IndexRead the element at the unsorted boundary is picked up, leaving a vacancy
  • Compare the picked-up element is tested against each sorted element from right to left; the scan stops as soon as a smaller-or-equal element is found
  • IndexWrite each losing sorted element shifts one step right to extend the vacancy; the picked-up element drops into the final vacancy when the scan stops
Initial State
This is the array before sorting. Follow Insertion sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 36 ops ( 0.0%) 0.0%
Sorting is
a spectacle.
Algorithms at work, in a daily vertical feed. Watch, play, challenge — and go deeper when you're ready.
Loading 0%
An unhandled error has occurred. Reload 🗙