sort.cny.shStart a race
Back to library
16 / 18Algorithm

Purge Sort

Just for fun: anything out of order is silently rewritten to fit.

StableIn-placeUnstable
BestO(n)
AverageO(n)
WorstO(n)
01How it works

Walk the array left-to-right tracking the running maximum. Anything that breaks the non-decreasing sequence is purged — here we overwrite it with the running max so the bar chart can keep its length. The result is technically sorted, just not the same data you started with.

02Best for

Joke talks, demonstrations of "lossy" algorithms, and reminding people that "the output is sorted" is not the same as "the output represents the input".

03Avoid when

Any time the values themselves matter. Half the input typically vanishes.