Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 最佳双音排序算法_Sorting - Fatal编程技术网

Sorting 最佳双音排序算法

Sorting 最佳双音排序算法,sorting,Sorting,我在研究双音排序算法 我意识到这种算法似乎有两种形式: 1 2 3 4 d c b a // start c d a b // compare (1, 2) (3, 4) a b c d // compare (1, 3) (2, 4) 维基百科算法 交替算法 (也是CUDA样本库中使用的样本) 维基百科算法: 1 2 3 4 d c b a // start c d a b // compare (1, 2) (3, 4) b a d c // compare (1, 4) (

我在研究双音排序算法

我意识到这种算法似乎有两种形式:

1 2 3 4

d c b a // start

c d a b // compare (1, 2) (3, 4)

a b c d // compare (1, 3) (2, 4)
维基百科算法

交替算法 (也是CUDA样本库中使用的样本)

维基百科算法:

1 2 3 4

d c b a // start

c d a b // compare (1, 2) (3, 4)

b a d c // compare (1, 4) (2, 3)

a b c d // compare (1, 2) (3, 4)
替代算法:

1 2 3 4

d c b a // start

c d a b // compare (1, 2) (3, 4)

a b c d // compare (1, 3) (2, 4)
在这个简单的例子中,替代算法似乎更有效

这两种算法等效吗

第一个有什么好处吗