简体   繁体   中英

Which sorting algorithm is faster?

Shell sort or odd-even transposition?

In my tests come Even-odd transposition sort is faster, correct?

It depends on your data layout.

But QuickSort is a pretty general purpose sorting algorithm if what you are going to sort is not huge. If you are planning to sort huge amounts of data, then you need something with intermediate memory such as MergeSort .

If I remember correctly, odd-even sort is very similar to bubble sort, but it can be executed in parallel.

On a single CPU core, Shell sort is generally better, but bubble/odd-even may win on small datasets.

In most cases it doesn't make sense to code your own sort algorithm. Nearly every environment has a built-in sort that should be your first choice. Even-odd transposition is O(n^2) for the worst data (on a single core).

Shell sort is faster for large arrays. How large you need to take the array before you see that depends on your implementation of both algorithms.

In most non-trivial case it does make sense to code your own sorting algorithm, but not all cases are non-trivial. It all depends on what you know about the data being sorted. There are even cases where bubblesort is a valid choice (or maybe even optimal).

Shell sort may be implemented with many variants of a initial gap size and its decrement in every step. The original algorithm is O(n^{3/2}) , but some improvements were presented by Hilberd, Sedgewick and Ciura. So if you are asking which is better, you must always say which implementation do you use. So a single core shell sort should win on every sufficiently large dataset. On multiple cores will probably win odd-even sort, because it can use more processing units.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM