algorithm - Java 中的流水线归并排序

标签 algorithm pipeline mergesort

<分区>

我用谷歌搜索了这个主题,所以我找到了一些东西:

Consider a pipeline of sorters S0 to Sm.

S0 has one input stream (the input sequence), and two output streams.
Si (i = 1 to m-1) has two input streams and two output streams. The
output streams of Si are the input streams of Si+1, for i = 0 to m-1.
Sm has two input streams and one output stream.

S0 reads the input stream, creates "sorted" sub-sequences of size one
and sends these intermittently to one of its two output streams.

Si repeatedly reads two sorted sub-sequences, one from each input
stream, merges them, and writes the double sized sorted sub-sequences
intermittently two one of its output streams.

Sm reads two sorted sub-sequences, one from each input stream, merges
these and produces the resulting output sequence.

Here is an example for a sequence of 8 numbers, where a bar | delimits
sorted sub sequences  

                  2 | 1 | 6 | 8  3 1 | 8 4  8 6 5 4 
7 2 3 1 5 6 4 8   ------------>  -------->  ------>   8 7 6 5 4 3 2 1
--------------> S0             S1         S2       S3 -------------->
                  ------------>  -------->  ------>
                  7 | 3 | 5 | 4  7 2 | 6 5  7 3 2 1 

我需要一些管道模式中合并排序的伪代码。

最佳答案

这看起来是 Bottom-Up Mergesort变体 (以及 herelecture notes here )使用“流”:

Bottom-up merge sort is a non-recursive variant of the merge sort, in which the array is sorted by a sequence of passes. During each pass, the array is divided into blocks of size m (Initially, m=1). Every two adjacent blocks are merged (as in normal merge sort), and the next pass is made with a twice larger value of m.

在 Pipeline Mergesort 中,每个排序器在组合相邻 block 时代表一次通过。然而,与更传统的自下而上合并排序不同的是,相邻 block 是从两个输入流中读取的匹配对(而不是在同一流/数组中相邻)。

在任何情况下,先尝试一些事情 -- SO 是一个提出实际问题的地方,而不是发布任务 :)

关于algorithm - Java 中的流水线归并排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12700632/

相关文章:

java - 合并排序在复制步骤中抛出 ArrayOutOfBounds 错误?

java - 我的合并排序的实现不起作用

java - ListUtils.intersection 中结果列表的顺序

algorithm - 如何知道一个二进制数是否被 3 整除?

scikit-learn - 管道: how determine feature names?中的python功能选择

c - C 中的 switch 语句会清空 x86 管道吗?

php - 按子数组值对数组进行分组

algorithm - 子集和 N 阵列解决方案,需要动态解决方案

arrays - 应使用什么语法来读取 Azure 数据工厂/Synapse 中“复制数据”事件的“映射”选项卡上数组的最后一行?

java - 自下而上合并排序代码的语法错误。我该如何解决?