The asymptotic lower bound for sorting n elements is n*log(n)

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
flufypancakes
Messages
11
Reaction score
0
the asymptotic lower bound for sorting n elements is n*log(n). what about sorting a set of n elements when you know that they only take on k distinct values? does n*log(k) sound right?
 
Physics news on Phys.org


Suppose that we could map each of the k values to the integers 1 to k. Also, suppose that we have k values in an array all set to 0. Then a sort would only look once at each number in a list. For each number the value is mapped to an index and the associated array element is incremented. Then the sort is completed by reporting as many values of each type as there are counts in each array element.

cost of inspecting each value n
+ cost of mapping each value from 1 to k ??
+ cost of outputting the sorted list k