473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

merge two binary trees

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

Feb 24 '06 #1
8 7795
sudharsan wrote:

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/>
Feb 24 '06 #2

CBFalconer wrote:
sudharsan wrote:

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.

--

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??

Feb 27 '06 #3

sudharsan wrote:
CBFalconer wrote:
sudharsan wrote:

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.

--

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.

--
BR, Vladimir

Feb 27 '06 #4
"Vladimir S. Oka" <no****@btopenworld.com> writes:
[...]
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?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 27 '06 #5
On 2006-02-27, Keith Thompson <ks***@mib.org> wrote:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
[...]
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"?

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.
Feb 27 '06 #6
Jordan Abel <ra*******@gmail.com> writes:
On 2006-02-27, Keith Thompson <ks***@mib.org> wrote:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
[...]
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 27 '06 #7
sudharsan wrote:
CBFalconer wrote:
sudharsan wrote:

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.


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/>
Feb 27 '06 #8
Keith Thompson wrote:
Jordan Abel <ra*******@gmail.com> writes:
On 2006-02-27, Keith Thompson <ks***@mib.org> wrote:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
[...]
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/>
Feb 28 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: abhrajit | last post by:
I'm looking for a C/C++/Java library to create a balanced binary tree data structure given a set of leaf nodes as input. A leaf node should never become an interior node. So if I wish to create...
4
by: Rasmus | last post by:
Hi. As partly novice in python I would like a piece of advise of how to implement (binary) trees the best way? Thanks in advance, Rasmus PS: Due to heavy spam reception (20.000+/week), I...
6
by: JC | last post by:
Hi, I'm looking for some help on Binary trees, in particular levels, heights etc. I need to find the levels of a tree, I also need to determine the minimum, maximum and average leaf levels. ...
1
by: Jerry Khoo | last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am > cs students and are now facing difficult problems in understanding > what a binary tree is, how it works, and the algorithm...
8
by: [diegueus9] Diego Andrés Sanabria | last post by:
Hello!!! I want know if python have binary trees and more?
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
10
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
2
by: pyguy | last post by:
Hi all, I am running into a conceptual glitch in implementing a simple binary tree class. My insertion and printing (sorting) seems to be ok, but when I search the tree, my find method isn't doing...
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.