|
|
|
|
|
by xvector
2349 days ago
|
|
Can you also hash every key to effectively turn them into a number, and then perform radix sort? If you hash with SHA-256 then any sorting operation seems like it’d just take O(256N)=O(N). What am I missing? Clearly this cannot work because otherwise everyone would do this as we accept O(NlogN) as the norm! |
|
Let's assume a perfect hash that never collides or leaves gaps, the best case for this.
For a radix sort in some base with K digits, N can only go so high before you have duplicates. Specifically, base^K >= N
Take the log of both sides. K >= logN
So with arbitrarily large numbers the time taken to sort is actually NlogN.
With fixed-size numbers it's "O(K*N)" but K is larger than logN would be.