What are the rules for the “Ω(n log n) barrier” for sorting algorithms?

前端 未结 2 1417
闹比i
闹比i 2020-11-28 02:17

I wrote a simple program that sorts in O(n). It is highly memory inefficient, but that\'s not the point.

It uses the principle behind a HashMap for sort

2条回答
  •  没有蜡笔的小新
    2020-11-28 03:04

    That is called Radix Sort, and yes it breaks the nlog(n) barrier, which is only a barrier on the Comparison Model. On the wikipedia page linked for Comparison Model you can see a list of sorts that use it, and a few that do not.

    Radix sort sorts by putting each element in a bucket, based on it's value and then concatenating all the buckets together again at the end. It only works with types like integers that have a finite number of possible values.

    Normally a radix sort is done one byte or nibble at a time to reduce the number of buckets. See the wikipedia article on it, or search for more info.

    Your's can also be made to sort negative numbers and only allocate memory for the buckets it uses to improve on it.

提交回复
热议问题