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

Picks up two elements at a time, a larger and a smaller, and inserts both into the sorted region in a single backward scan, placing the larger first and then continuing the scan to place the smaller.

🎯 Key property

The smaller element always terminates the backward scan before or at the point where the larger stopped, so the combined scan is shorter than two independent insertions, roughly halving total comparisons.

👁 Watch for
  • IndexRead two elements are picked up from the unsorted boundary; the larger is queued for insertion first since it requires the longer scan
  • Compare the backward scan finds the larger element's stopping point first; the smaller then continues from that point with a narrowed search range
  • IndexWrite sorted elements shift right to open two adjacent vacancies; both picked-up elements drop into place in a single continuous backward pass
Initial State
This is the array before sorting. Follow Pair insertion sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 83 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 🗙