Counting sort
mediumTally the values, turn the tallies into positions with a prefix sum, then place each element directly. The comparison counter stays at zero for the whole run - this is not bound by the Ω(n log n) lower bound.
Best
O(n + k)Average O(n + k)Worst O(n + k)Space O(n + k)StableNeeds extra memoryLoading the counting sort engine…