473,397 Members | 2,033 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,397 software developers and data experts.

Binary trees

- with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
- what is the advantage of having a balanced binary tree over an
unbalanced tree?
- number your nodes, then give the order in which nodes will be
visited by a depth-first-search
- explain the differences between traversing the tree pre-order, in-
order and post-order

May 4 '07 #1
8 3258
In article <11**********************@h2g2000hsg.googlegroups. com>,
<n.******@gmail.comwrote:
- with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
Example of a balanced binary tree: [IMAGE]
Example of an unbalanced binary tree: [IMAGE]
- what is the advantage of having a balanced binary tree over an
unbalanced tree?
A balanced tree won't fall over when you stop holding it.
- number your nodes, then give the order in which nodes will be
visited by a depth-first-search
42, pi, 17, e, 105, 69, i, sqrt(2), 3, -1.
- explain the differences between traversing the tree pre-order, in-
order and post-order
The order you traverse it in is different.

DYODH.

dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Hey, I can beat him on the Impressive But Useless certificates thing.
I have a PhD.
--Dan Holdsworth in the scary devil monastery
May 4 '07 #2
n.******@gmail.com wrote:
- with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
Unbalanced tree: AB,C'K:D'EH:FJ:G: (notation adapted
from Knuth, TAOCP 2.3.3 equation 3)

To balance the tree, put another one on the other pan.
- what is the advantage of having a balanced binary tree over an
unbalanced tree?
Easier access to firewood. When the next high wind topples
the unbalanced tree, the balanced tree that's over it will fall
at the same time and save you the work of cutting it down.
- number your nodes, then give the order in which nodes will be
visited by a depth-first-search
Numbers: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

Depth-first order: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
- explain the differences between traversing the tree pre-order, in-
order and post-order
With pre-order, the pizza is ready when you arrive at the
shop and you needn't wait. With in-order, you may need to pay
a restaurant tax to eat the pizza on the premises. With post-
order, the pizza reaches you three to five business days later
and is unpalatable.

--
Eric Sosman
es*****@acm-dot-org.invalid

May 4 '07 #3
n.******@gmail.com wrote:
- with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
- what is the advantage of having a balanced binary tree over an
unbalanced tree?
- number your nodes, then give the order in which nodes will be
visited by a depth-first-search
- explain the differences between traversing the tree pre-order, in-
order and post-order
I think you should have posted to comp.lazy.domyhomework, since (a)
this is homework; having someone else do it for you misses the point;
(b) it's off-topic, since it isn't about C at all.

--
Not A Number, A Free Hedgehog
Meaning precedes definition.

May 4 '07 #4
n.******@gmail.com wrote:
- with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
http://en.wikipedia.org/wiki/Binary_tree
- what is the advantage of having a balanced binary tree over an
unbalanced tree?
A balanced tree will not fall over in a storm, as long as the wind blows
evenly from all directions.
- number your nodes, then give the order in which nodes will be
visited by a depth-first-search
http://en.wikipedia.org/wiki/Binary_...th-first_order
- explain the differences between traversing the tree pre-order, in-
order and post-order
http://en.wikipedia.org/wiki/Binary_...rder_traversal.

--
clvrmnky

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
May 4 '07 #5
In article <6N****************@nnrp.ca.mci.com!nnrp1.uunet.ca >,
Clever Monkey <sp******@clevermonkey.org.INVALIDwrote:
>n.******@gmail.com wrote:
> - what is the advantage of having a balanced binary tree over an
unbalanced tree?
A balanced tree will not fall over in a storm, as long as the wind blows
evenly from all directions.
But the wind in most storms doesn't blow evenly from all directions.
If you're going for storm tolerance, you really want an unbalanced tree,
but the problem with that is that every time the wind changes you have
to go out and re-unbalance it for the new wind direction.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
And there was nothing insulting about it. Some people would rather
take being called a ``normal person'' as an insult.
--Nils Goesche in comp.lang.c
May 4 '07 #6
In article <mc******************************@comcast.com>,
Eric Sosman <es*****@acm-dot-org.invalidwrote:
>n.******@gmail.com wrote:
> - with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree

Unbalanced tree: AB,C'K:D'EH:FJ:G: (notation adapted
from Knuth, TAOCP 2.3.3 equation 3)
Unless you have a different edition than I do (3rd), I think you meant
equation 4.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
The DS 9000 is a conforming implementation.
The DS 9001 is so cleverly designed that experts can't agree whether it
is conforming or not! --Christian Bau in comp.lang.c
May 4 '07 #7
Dave Vandervies wrote On 05/04/07 16:08,:
In article <mc******************************@comcast.com>,
Eric Sosman <es*****@acm-dot-org.invalidwrote:
>>n.******@gmail.com wrote:
>> - with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree

Unbalanced tree: AB,C'K:D'EH:FJ:G: (notation adapted
>>from Knuth, TAOCP 2.3.3 equation 3)

Unless you have a different edition than I do (3rd), I think you meant
equation 4.
The renumbering was part of the adaptation.

--
Er*********@sun.com
May 4 '07 #8
Dave Vandervies wrote:
In article <6N****************@nnrp.ca.mci.com!nnrp1.uunet.ca >,
Clever Monkey <sp******@clevermonkey.org.INVALIDwrote:
>n.******@gmail.com wrote:
>> - what is the advantage of having a balanced binary tree over an
unbalanced tree?
A balanced tree will not fall over in a storm, as long as the wind blows
evenly from all directions.

But the wind in most storms doesn't blow evenly from all directions.
If you're going for storm tolerance, you really want an unbalanced tree,
but the problem with that is that every time the wind changes you have
to go out and re-unbalance it for the new wind direction.
So true. I think I'm barking up the wrong tree here. We better leaf
this alone for while, or we might end up branching off into the wrong
direction. If I twig onto anything else, I'll let you know, but I think
this conversation will not bear any new fruit. Either that, or I'm the
fall guy and can't see the tree for the forest.

--
clvrmnky

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
May 4 '07 #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...
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...
3
by: ptrSriram | last post by:
Can someone help me with an algorithm to merge two binary search trees. One method I thought of was to flatten both the trees into sorted lists(inorder traversal),merge those two sorted lists,...
8
by: sudharsan | last post by:
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...
0
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...
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
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
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...

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.