 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri May 04, 2007 4:55 am Post subject: 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 |
|
| Back to top |
|
 |
Dave Vandervies Guest
|
Posted: Fri May 04, 2007 4:55 am Post subject: Re: Binary trees |
|
|
In article <1178236539.346703.194270 (AT) h2g2000hsg (DOT) googlegroups.com>,
<n.noumia (AT) gmail (DOT) com> wrote:
| Quote: | - 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]
| Quote: | - 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.
| Quote: | - 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.
| Quote: | - 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 dj3vande (AT) csclub (DOT) 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 |
|
| Back to top |
|
 |
Eric Sosman Guest
|
Posted: Fri May 04, 2007 7:56 am Post subject: Re: Binary trees |
|
|
n.noumia (AT) gmail (DOT) com wrote:
| Quote: | - with 10 nodes, give one example of an unbalanced binary tree and
one example of a balanced binary tree
|
Unbalanced tree: AB,C'K 'EH:FJ:G: (notation adapted
from Knuth, TAOCP 2.3.3 equation 3)
To balance the tree, put another one on the other pan.
| Quote: | - 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.
| Quote: | - 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
| Quote: | - 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
esosman@acm-dot-org.invalid |
|
| Back to top |
|
 |
Chris Dollin Guest
|
Posted: Fri May 04, 2007 9:12 am Post subject: Re: Binary trees |
|
|
n.noumia (AT) gmail (DOT) com wrote:
| Quote: | - 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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|