我有一个关于提议的soln的查询 Algorithm for N-way merge
成员aioobe提出的解决方案如下:
1. Create a priority queue
2. Iterate through each file f
enqueue the pair (nextNumberIn(f), f) using the first value as priority key
3. While queue not empty
1. dequeue head (m, f) of queue
2. output m
3. if f not depleted
1. enqueue (nextNumberIn(f), f)
我完全不理解第2步和第3步。步骤2是否需要将所有文件的内容读入优先级队列?如果是这样的话,记忆不会成为一个问题吗?
在第3步中,我不理解3.3(如果f没有消耗,则排队)。 可能有人或OP(aioobe)帮助我理解这一点。非常感谢。
答案 0 :(得分:1)
步骤2仅从每个文件中读取第一个数字。它不应该是内存问题,除非你有大量的文件或非常大的数字。
步骤3.3读取m来自m的同一文件中的下一个数字。