Suppose we have k streams { s0,s1,s2,s3,...,sk }. Each stream contains integers in sorted order, and each stream could potentially be infinite in length. How would you merge these k streams into a new stream S, such that S is in sorted order. Do this as efficiently as possible.
*BY sorted order, i mean that element i is >= element i-1 for all i.
*A stream is just basically an abstraction of a list. All you can do is view the current element, or advance the stream to the next element.
for instance if i have a stream of the set of integers > 0 = {1,2,3,....} and the start of the stream is the 0th element = 1
I can view the current element (1) or i can advance the stream to index 1 and so forth. Get it?
This is enough information to do the problem. It's trickier than you might think. Keep in mind, there is the obvious solution, and then the optimal solution.
*BY sorted order, i mean that element i is >= element i-1 for all i.
*A stream is just basically an abstraction of a list. All you can do is view the current element, or advance the stream to the next element.
for instance if i have a stream of the set of integers > 0 = {1,2,3,....} and the start of the stream is the 0th element = 1
I can view the current element (1) or i can advance the stream to index 1 and so forth. Get it?
This is enough information to do the problem. It's trickier than you might think. Keep in mind, there is the obvious solution, and then the optimal solution.