473,626 Members | 3,351 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 4351

"Jerry Khoo" <je*********@ya hoo.com> wrote in message
news:b6******** *************** **@posting.goog le.com...
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*********@ya hoo.com> wrote in message
news:b6******** *************** **@posting.goog le.com...
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
3398
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 display, > arrange, find, delete the leaf node in binary tree. > > I hope that anyone with expereince in building binary tree could help > me in explaining the binary tree functions, and give a sample code of > the whole picture behind the...
8
2768
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 display, arrange, find, delete the leaf node in binary tree. I hope that anyone with expereince in building binary tree could help me in explaining the binary tree functions, and give a sample code of the whole picture behind the tree. And...
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 recursive function to build it up, but than is there any way around i could built a tree using iterative method like for .. loop?
7
3637
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
9561
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
5085
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 lists. I'm totally new to binary searches by the way. Can anyone help me with the commented sections below? Much of the code such as functions and printfs has already been completed. Any help is greatly appreciated. Thanks,
4
2947
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 looks the data up in the tree.
3
4432
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 decided that the most effective way would be : When i connect to the server once, I download the list and disconnect, instead of connecting every time i go, to the lower node in my tree hierarhy. Thus i have a problem - how to store data.
6
16868
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 according to your hash function you might take more memory than binary tree. On the contrary, binary tree gives you O(logN) searching but less memory. Am I right?
3
2452
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 when i try to built the secund node ,i dont anderstend whay, my program write to my new node and to first tree node; string readLine(istream& fin) { char buff; // Clear any remaining end of line characters if(fin.peek()=='\n') {...
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8504
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.