Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an O(n) integer sorting algorithm?

The last week I stumbled over this paper where the authors mention on the second page:

Note that this yields a linear running time for integer edge weights.

The same on the third page:

This yields a linear running time for integer edge weights and O(m log n) for comparison-based sorting.

And on the 8th page:

In particular, using fast integer sorting would probably accelerate GPA considerably.

Does this mean that there is a O(n) sorting algorithm under special circumstances for integer values? Or is this a specialty of graph theory?

PS:
It could be that reference [3] could be helpful because on the first page they say:

Further improvements have been achieved for [..] graph classes such as integer edge weights [3], [...]

but I didn't have access to any of the scientific journals.

like image 346
Karussell Avatar asked Feb 28 '10 19:02

Karussell


People also ask

Is it possible to have an O of n sorting algorithm?

Yes, Radix Sort and Counting Sort are O(N) . They are NOT comparison-based sorts, which have been proven to have Ω(N log N) lower bound. To be precise, Radix Sort is O(kN) , where k is the number of digits in the values to be sorted.

Can you sort in O n time?

If you consider given 750 as constant, it sorts at O(n). Comparison based sorting can't sort in less than O(nlogn), but if number of values is bounded by D, you can sort in O(D*n), or O(n) if you consider D as constant. Sure its a theorem. Any comparison algorithm is O(n log n).

Which sorting algorithm is best for integers?

If you recall radix sort or bucket sort, you will notice that their running times are O(n). Since all sorting algorithms are bound below by Ω(n), I would argue that both radix sort and bucket sort are the fastest algorithms for sorting an array of integers.


2 Answers

Yes, Radix Sort and Counting Sort are O(N). They are NOT comparison-based sorts, which have been proven to have Ω(N log N) lower bound.

To be precise, Radix Sort is O(kN), where k is the number of digits in the values to be sorted. Counting Sort is O(N + k), where k is the range of the numbers to be sorted.

There are specific applications where k is small enough that both Radix Sort and Counting Sort exhibit linear-time performance in practice.

like image 168
polygenelubricants Avatar answered Sep 19 '22 17:09

polygenelubricants


Comparison sorts must be at least Ω(n log n) on average.

However, counting sort and radix sort scale linearly with input size – because they are not comparison sorts, they exploit the fixed structure of the inputs.

like image 34
ephemient Avatar answered Sep 21 '22 17:09

ephemient