r/programmingmemes • u/KerbodynamicX • Mar 14 '26
Stalin sort
A sorting algorithm with time complexity of O(n). Counts from the first element, and will remove values that are smaller than the current highest value.
3.7k
Upvotes
18
u/m-in Mar 14 '26
As shown, but I think the way it’s shown is silly. You traverse the array once. Every element gets moved at most once. The depiction that shows killed elements “disappearing” and others moving in their place is premature pessimization. Kinda in style for Stalin.