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? 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
"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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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
/ \ / \ / \
|
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
/ \ / \ / \
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |