Sort Target
Algorithm
Speed
Normal ~12s · 140 ms/step
Patience sort(1962)
▶ Try this Source
O(n log n) ✗ Stable ✗ In-place
🔧 How it works

Deals each element onto the leftmost pile whose top is greater than or equal to the element (found via binary search), starting a new pile if none qualifies. Then uses a k-way min-heap merge to pull the global minimum from all pile tops repeatedly until the sorted output is complete.

🎯 Key property

The number of piles equals the length of the Longest Increasing Subsequence (LIS) of the input. On already-sorted data only one pile is created and the algorithm runs in O(n); on reverse-sorted data n piles are created and the cost is O(n log n).

👁 Watch for
  • Compare (pile building) binary search over pile tops finds the leftmost pile whose top >= the incoming element in O(log k) per element, maintaining the invariant that pile tops are non-decreasing left to right
  • IndexWrite (dealing) the element is placed on the chosen pile, becoming its new top; pile tops always stay non-decreasing after each placement
  • Compare (k-way merge) a min-heap of size k holds the current top of every pile; each heap extraction identifies the global minimum across all pile tops in O(log k)
  • IndexWrite (merge output) the extracted minimum is written to the output buffer in sorted order; its pile is popped and re-heapified if non-empty
Initial State
This is the array before sorting. Follow Patience sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
Patience PilesDeal 0 piles
Waiting for sort to begin…
0 / 86 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 🗙