Coordinate Compression
Sort the distinct values and replace each value by its rank; order survives, the range shrinks.
Decision · step 2 of 9Rotate, Partition, Select: Coordinate compression
100 is the 3rd smallest distinct value, so it becomes 2.
What you will see
Values sort and deduplicate; each original maps to its rank.
Cost
| Best | O(n log n) |
|---|---|
| Average | O(n log n) |
| Worst | O(n log n) |
| Space | O(n) |
How you work with it here
play it through, step one change at a time, run it on your own input, predict what happens next.
Screen readers: Pattern lessons reuse the canonical algorithm's semantics and add a spoken "recognize this when" cue.
Reduced motion: Inherits the canonical algorithm's strategy.
Before this
Taught by the same lesson
Rotate, Partition, Select covers these too, in the same run.