如何解决对非常大的列表进行排序的问题?
我想我们划分列表并让它们在每个 CPU 中处理并生成小的排序列表。
但是我们如何组合并生成最终的排序列表呢?
最佳答案
您可以使用 priority queu 合并多个排序列表e(基于二叉堆)。
用对 (列表的当前元素或其索引;列表 id)
填充队列。
At every step:
extract pair with min element from queue
add value to result
get the next element of the same list (if possible)
insert new pair into queue again
相对于可用内存,您的列表有多大?
有用的线索从wiki external sorting page开始
关于algorithm - 合并排序的 n 个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51393954/