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

Repeatedly extracts sorted subsequences ('strands') from the remaining elements and merges each strand into the accumulated result until the input is exhausted. Each extraction pass greedily builds the longest non-decreasing run starting from the first remaining element, scanning left to right; elements that fit are appended to the strand, others are compacted back into the remaining pool in place.

🎯 Key property

On already-sorted input the entire array forms one strand and the algorithm runs in O(n). On reverse-sorted input every strand has length 1, producing n strands and O(n²) total work. Random input typically yields O(√n) strands, giving O(n√n) average cost.

👁 Watch for
  • Compare (strand extraction) each remaining element is compared against the current strand tail; elements ≥ the tail are appended to the strand, others are compacted back into the remaining pool
  • IndexWrite (merge) the extracted strand and the accumulated result are merged by a standard 2-way merge, writing the smaller front element each step directly to the main buffer
  • IndexRead / IndexWrite (result save) after each non-final merge the merged output is copied to the result buffer so the next pass can merge against it; the final pass leaves the sorted data in the main buffer without an extra copy
Initial State
This is the array before sorting. Follow Strand sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 107 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 🗙