473,499 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

building up binary tree

Thanks for the answer, and by the way, i would like to know that in
C++,
how u create a tree using a recursive envronment[ i mean how to
allocate memory, to connect to each node, how to display the binary
tree content, deleting a node, and adding a node]. It seems that most
people used struct to create a node than, using recursive function to
build it up, but than is there any way around i could built a tree
using iterative method like for .. loop?
Jul 22 '05 #1
4 4339

"Jerry Khoo" <je*********@yahoo.com> wrote in message
news:b6*************************@posting.google.co m...
Thanks for the answer, and by the way, i would like to know that in
C++,
how u create a tree using a recursive envronment[ i mean how to
allocate memory, to connect to each node, how to display the binary
tree content, deleting a node, and adding a node]. It seems that most
people used struct to create a node than, using recursive function to
build it up, but than is there any way around i could built a tree
using iterative method like for .. loop?


No. Trees are recursive structures and are therefore most naturally dealt
with using recursive algorithms. Any attempt to use an iterative algorithm
gets horrendously complex very quickly.

john
Jul 22 '05 #2

"Jerry Khoo" <je*********@yahoo.com> wrote in message
news:b6*************************@posting.google.co m...
Thanks for the answer, and by the way, i would like to know that in
C++,
how u create a tree using a recursive envronment[ i mean how to
allocate memory, to connect to each node, how to display the binary
tree content, deleting a node, and adding a node]. It seems that most
people used struct to create a node than, using recursive function to
build it up, but than is there any way around i could built a tree
using iterative method like for .. loop?


No. Trees are recursive structures and are therefore most naturally dealt
with using recursive algorithms. Any attempt to use an iterative algorithm
gets horrendously complex very quickly.

john
Jul 22 '05 #3
Jerry Khoo wrote:

Thanks for the answer, and by the way, i would like to know that in
C++,
how u create a tree using a recursive envronment[ i mean how to
allocate memory, to connect to each node, how to display the binary
tree content, deleting a node, and adding a node]. It seems that most
people used struct to create a node than, using recursive function to
build it up, but than is there any way around i could built a tree
using iterative method like for .. loop?


Yes. Each recursive algorithm can be written as an iterative one.
However, for most you will need to explicitely use some kind of stack
structure (e.g. to remember the current path in the tree). Using
recursive functions, the system stack does this bookkeeping for you.

Expressing tree algorithms using recursive functions is simple compared
to iterative versions. Recursive algorithms are most of the time
somewhat slower (there can be a lot of function calls) but probably this
does not matter for your application. Recursive algorithms can use a lot
of (sometimes too much) stack memory, but most of the time this is not
problematic (because in many applications, the tree depth is typically
logarithmic in the total number of nodes in the tree).

Best regards,
Ares Lagae
Jul 22 '05 #4
Jerry Khoo wrote:

Thanks for the answer, and by the way, i would like to know that in
C++,
how u create a tree using a recursive envronment[ i mean how to
allocate memory, to connect to each node, how to display the binary
tree content, deleting a node, and adding a node]. It seems that most
people used struct to create a node than, using recursive function to
build it up, but than is there any way around i could built a tree
using iterative method like for .. loop?


Yes. Each recursive algorithm can be written as an iterative one.
However, for most you will need to explicitely use some kind of stack
structure (e.g. to remember the current path in the tree). Using
recursive functions, the system stack does this bookkeeping for you.

Expressing tree algorithms using recursive functions is simple compared
to iterative versions. Recursive algorithms are most of the time
somewhat slower (there can be a lot of function calls) but probably this
does not matter for your application. Recursive algorithms can use a lot
of (sometimes too much) stack memory, but most of the time this is not
problematic (because in many applications, the tree depth is typically
logarithmic in the total number of nodes in the tree).

Best regards,
Ares Lagae
Jul 22 '05 #5

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

Similar topics

1
3381
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
2750
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 to...
4
806
by: Jerry Khoo | last post by:
Thanks for the answer, and by the way, i would like to know that in C++, how u create a tree using a recursive envronment. It seems that most people used struct to create a node than, using...
7
3611
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
5
9549
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
15
5064
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...
4
2939
by: Ken | last post by:
I have a binary tree in VB NET and insertions seem to be slow. The program receives data from one source and inserts it into the tree. The program receives data from another source and...
3
4422
by: piotrek | last post by:
Hi I would like to ask you a question. Ian creating app. that download from server directory structure ( whole tree ) and those data are placed in proper places into my treeview control. I...
6
16854
by: fdmfdmfdm | last post by:
This might not be the best place to post this topic, but I assume most of the experts in C shall know this. This is an interview question. My answer is: hash table gives you O(1) searching but...
3
2441
by: FARAECHILIBRU | last post by:
i'm building a binary tree the problem is when i'm reading from e text file .First i'm sending to tree builder function a empty node and e new node the function return me firt node of a tree, but...
0
7006
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
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6892
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
7385
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
5467
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,...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.