sorting-network

Fast algorithm implementation to sort very small list

丶灬走出姿态 提交于 2019-12-17 06:02:10
问题 This is the problem I ran into long time ago. I thought I may ask your for your ideas. assume I have very small list of numbers (integers), 4 or 8 elements, that need to be sorted, fast. what would be the best approach/algorithm? my approach was to use the max/min functions (10 functions to sort 4 numbers, no branches, iirc). // s(i,j) == max(i,j), min(i,j) i,j = s(i,j) k,l = s(k,l) i,k = s(i,k) // i on top j,l = s(j,l) // l on bottom j,k = s(j,k) I guess my question pertains more to

Optimal 9-element sorting network that reduces to an optimal median-of-9 network?

非 Y 不嫁゛ 提交于 2019-12-04 08:42:24
问题 I am looking into sorting and median-selection networks for nine elements based exclusively on two-input minimum / maximum operations. Knuth, TAOCP Vol. 3 , 2nd ed. states (page 226) that a nine-element sorting network requires at least 25 comparisons, which translates into an equal number of SWAP() primitives or 50 min / max operations. Obviously a sorting network can be converted into a median-selection network by eliminating redundant operations. The conventional wisdom seems to be that

Standard sorting networks for small values of n

吃可爱长大的小学妹 提交于 2019-11-30 13:21:08
问题 I'm looking for a sorting network implementation of a 5-element sort, but since I couldn't find a good reference on SO, I'd like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A good answer should at least list them as sequences of "swap" (sort on 2 elements) operations, but it might also be nice to see the recursive decomposition in terms of lower-order sorting networks. For my application, I actually only care about the

Standard sorting networks for small values of n

一笑奈何 提交于 2019-11-30 06:52:38
I'm looking for a sorting network implementation of a 5-element sort, but since I couldn't find a good reference on SO, I'd like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A good answer should at least list them as sequences of "swap" (sort on 2 elements) operations, but it might also be nice to see the recursive decomposition in terms of lower-order sorting networks. For my application, I actually only care about the median of 5 elements, not actually putting them in order. That is, the order of the other 4 elements

How to fix this non-recursive odd-even-merge sort algorithm?

隐身守侯 提交于 2019-11-30 03:16:33
问题 I was searching for non-recursive odd-even-merge sort algorithm and found 2 sources: a book from Sedgewick R. this SO question Both algorithms are identical but false. The resulting sorting network is not an odd-even-merge sort network. Here is an image of the resulting network with 32 inputs. A vertical line between 2 horizontal lines means compare value a[x] with a[y], if greater then swap the values in the array. (source: flylib.com) (clickable) I copied the code from Java to C and

Fastest sort of fixed length 6 int array

烂漫一生 提交于 2019-11-26 00:38:57
问题 Answering to another Stack Overflow question (this one) I stumbled upon an interesting sub-problem. What is the fastest way to sort an array of 6 integers? As the question is very low level: we can\'t assume libraries are available (and the call itself has its cost), only plain C to avoid emptying instruction pipeline (that has a very high cost) we should probably minimize branches, jumps, and every other kind of control flow breaking (like those hidden behind sequence points in && or || ).