Sort Target
Algorithm
Speed
Normal ~12s · 107 ms/step
Pingpong merge sort(2014)
▶ Try this Source
O(n log n) ✓ Stable ✗ In-place
🔧 How it works

Recursively splits the array in half like standard Merge sort, but uses two full-size buffers that alternate roles at every recursion level, one buffer is the source (ping) and the other is the destination (pong), swapping at each recursive call.

🎯 Key property

Eliminating the copy-back step of standard Merge sort reduces writes from 1.5n per level to n per level, roughly 33% fewer total writes for large arrays. The result always surfaces in the original array so no final copy-back is needed.

👁 Watch for
  • RangeCopy the entire input is copied into the auxiliary buffer before recursion begins so both buffers hold valid data; leaf-level copies (dst[i] = src[i]) correctly read from whichever buffer is the current source at that recursion depth
  • Compare a skip-sorted check (src[mid] ≤ src[mid+1]) fires before each merge; when the two halves are already in order the merge is replaced by a single bulk copy instead of per-element comparisons
  • IndexWrite during each merge, elements are written directly from the source buffer to the destination buffer without any intermediate scratch space; the buffers swap roles at each recursive level so the sorted result always lands in the original array
Initial State
This is the array before sorting. Follow Pingpong merge sort step by step.
Recursion Tree
[0..8)53819274
0 / 112 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 🗙