English 中文(简体)
分类阵列要素的算法是什么?
原标题:What is the most performant algorithm for sorting array elements?

I am solving UVa site problems, I have a problem that I must sort the integers as fast as possible.

我尝试了这种泡沫,但效率不高。 我尝试了快速的,它使用回收,但产生了一个<>StackOverflowException,因为输入量很大(,近2 000万)。

问题时限仅为5秒。 是否有任何想法说明如何更有效地执行?

最佳回答

Since you re only sorting integers, radix sort might be a good idea. The nice thing about this algorithm is that its always taking the same amount of time which is dependent on the number of elements to sort and not how "unsorted" they are.

See also Donald Knuth s The Art of Computer Programming volume 3, Sorting and Searching. The algorithm is described in section 5.2.5. Sorting by Distribution, starting at page 168. The algorithm s pseudo-code is Algorithm R on page 172 (page numbers from second edition).

不仅算法效率很高,而且我认为它容易理解和执行(特别是分类算法)。

问题回答

You don t necessarily need to write quicksort recursively.

你们可以采用休养算法,改用分法,避免再入侵。

例例:

下面是你认为不兼容的建议。 你们说,重新分类愤怒......究竟是允许什么类型的愤怒? 计票/包裹会很快。

我利用C和qsort(功能)解决了这一问题,让这一尝试得以进行。

可在in-place上书写。 由于不需要(更多,而不是太多)额外记忆,我认为,如果你使用这一版本,那不会造成错误。 如果你仍有这种错误,你可以考虑随意输入。

另外,您也可考虑非对等,例如counting,。 这些类型的算法有其局限性,但通常需要较少的时间,例如O(n)。





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...