I have a query with regard to one of the soln proposed for Algorithm for N-way merge
The soln proposed by member aioobe is as follows:
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)
I did not understand steps 2 and 3 completely. Does step 2 need to read contents of all files into priority queue ? If that's the case, won't memory be a concern?
In step 3, i did not understand 3.3 (if f not deplete, enqueue). Could some one or the OP (aioobe) help me here to understand this. Many thanks.