On 1/18/06, [EMAIL PROTECTED] <[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).
// assuming that you sort from the lowest to the highest value
while (there are elements in one of the k streams) {
  v[] = {next element of each stream};  // put in an array the next
element of each stream
  vi = lowest_index(v);  // the index of the array of the lowest
element (in sort order)
  put v[vi] into the destination stream;
  v[vi] = streams[vi].get_next_value;  // replace the used value with
the next of his stream
}
[ you need to handle the case where a stream reaches the end, but
you can use a conventional value in the array]

I hope it's clear enough, otherwise send a line here !

I hope I correctly understood the problem ...:)

> Given a binary tree with the following constraints:
> a) A node has either both a left and right child OR no children
> b) The right child of a node is either a leaf or NULL
> write code to invert this tree.
> I can write a recursive code to invert just about any binary tree but i
> dont understand whats so special abt the 2 constraints .
IMHO there's nothing special ...

bye !!!

mattia.

Reply via email to