merge two binary trees

S

sudharsan

please gimme the logic to merge two binary search trees?I mean which
node has to be the root node of the new binary tree??
Thanks in advance
 
C

CBFalconer

sudharsan said:
please gimme the logic to merge two binary search trees?I mean which
node has to be the root node of the new binary tree??
Thanks in advance

Thanks for monitoring this newsgroup and being aware of what is and
is not topical for it. In the same spirit of co-operation, I offer
the following accurate method:

Install all items in a new tree, using only the left pointer, and
setting all the new right pointers to NULL. Extract the items from
the original trees with an inorder treewalk. When done, sort the
resultant list formed with the left pointers with mergesort. The
result will be a binary search tree.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
S

sudharsan

CBFalconer said:
Thanks for monitoring this newsgroup and being aware of what is and
is not topical for it. In the same spirit of co-operation, I offer
the following accurate method:

Install all items in a new tree, using only the left pointer, and
setting all the new right pointers to NULL. Extract the items from
the original trees with an inorder treewalk. When done, sort the
resultant list formed with the left pointers with mergesort. The
result will be a binary search tree.

--
thanks cbfalconer,
but i cudnot understand "Extract the items from
the original trees with an inorder treewalk" original tree???which one
.....of the two sorted binary tree??
 
V

Vladimir S. Oka

sudharsan said:
thanks cbfalconer,
but i cudnot understand "Extract the items from
the original trees with an inorder treewalk" original tree???which one
....of the two sorted binary tree??

You didn't get it did you? Let me spell it out:

Your question is off-topic here. Please take it to a better group. Our
neighbours in comp.programming (down the hall, second door on the
right) may be able to help. When you next have a question that involves
C programming language, feel free to call again.
 
C

CBFalconer

sudharsan said:
thanks cbfalconer,
but i cudnot understand "Extract the items from
the original trees with an inorder treewalk" original tree???
which one....of the two sorted binary tree??

The method will work, but will be degenerate. The point is that
the question has nothing to do with the subject of this newsgroup.
If you don't understand you need to do some studying of elementary
algorithms, which again is not topical here. I suggest getting and
reading Sedgwicks "Algorithms" or "Algorithms in C".

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
K

Keith Thompson

Vladimir S. Oka said:
Your question is off-topic here. Please take it to a better group. Our
neighbours in comp.programming (down the hall, second door on the
right) may be able to help. When you next have a question that involves
C programming language, feel free to call again.

I thought comp.lang.c++ was the second door on the right. Or did you
go down the hall in the opposite direction?
 
J

Jordan Abel

I thought comp.lang.c++ was the second door on the right. Or did you
go down the hall in the opposite direction?

Wouldn't you then say "up the hall"?

Clearly, the second door on the right leads to a dead-end mini-hallway
with two doors in it leading to the rooms in question.
 
C

CBFalconer

Keith said:
Jordan Abel said:
[...]
Your question is off-topic here. Please take it to a better group.
Our neighbours in comp.programming (down the hall, second door on
the right) may be able to help. When you next have a question that
involves C programming language, feel free to call again.

I thought comp.lang.c++ was the second door on the right. Or did
you go down the hall in the opposite direction?

Wouldn't you then say "up the hall"?

Obviously we're at the high point of the hall, so it's "down" in
both directions.

You can't go up. Maybe you should drop something, or turn off the
lamp to conserve batteries.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top