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

AI Thread Summary
The asymptotic lower bound for sorting n elements is established as n*log(n). However, when sorting n elements with k distinct values, the complexity can be reduced to n*log(k). This is achieved by mapping each of the k distinct values to integers from 1 to k. The sorting process involves iterating through the list of n elements, incrementing counts in an auxiliary array for each distinct value. The overall cost includes inspecting each value (n), the cost of mapping values (which remains to be determined), and the cost of outputting the sorted list (k). This method highlights the efficiency gained when the number of distinct values is significantly smaller than the total number of elements, optimizing the sorting process.
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?
 
Technology 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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top