pseudo algo:
=>array idx[0...k-1] .... indicates the current pointer position in the ith
stream(initialized to 0).
=>heap tree of size k where each node stores value of the data and value of
stream which the node belongs to.
do{
for all i = 0:k-1
=>insert idx[i] value of ith stream to the heap
=>take the root element of the heap and put it in the output stream.
=>idx[m]++ where m is the stream value stored at the root.
} while(true);
On Sat, Sep 10, 2011 at 12:15 AM, aditya kumar <[email protected]
> wrote:
> Given k sorted streams where each stream could possibly be infinite in
> length, describe an efficient algorithm to merge the k streams into a new
> stream (also in sorted order).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.