Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: no :of node...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 18 Topic 26106 of 26821
Post > Topic >>

Re: no :of nodes

by Eric Sosman <esosman@[EMAIL PROTECTED] > May 8, 2008 at 08:36 AM

Keith Thompson wrote:
> Thad Smith <ThadSmith@[EMAIL PROTECTED]
> writes:
>> Eric Sosman wrote:
>>> sophia wrote:
>>>> How good is this function which is used to find  the no: of nodes
>>>> in each level of the binary tree. ?
> 
> [snip]
> 
>>>     4) You might gain still more speed by using recursion only
>>> when you encounter a node where both the left and right branches
>>> are non-NULL.  This also offers some defense against degeneracy.
>> I'd say that 4) offers excellent defense against (call level overflow)
>> degeneracy since the maximum recursion level is less than log2(N)+1.
> 
> Does it?  It limits recursion if the tree is a linear vine, and can
> reduce it substantially in some other cases, but what if each node on
> the leftmost vine has a single node as its right child?  Then the
> depth of recursion could be on the order of 1/2 the number of nodes.
> [...]

     That's why I only claimed "some" defense against degeneracy.
Even in the tree you describe one might get lucky: if when
faced with a two-way branch the function always recursed to the
right and looped to the left, there'd be no trouble.  Of course,
then a tree that leaned the other direction would be bad.  So
would a zig-zag arrangement where the "trunk" went left and right
alternately while the "twigs" branched right and left.

-- 
Eric Sosman
esosman@[EMAIL PROTECTED]

 




 18 Posts in Topic:
no :of nodes
sophia <sophia.agnes@[  2008-05-07 11:16:16 
Re: no :of nodes
roberson@[EMAIL PROTECTED  2008-05-07 18:30:53 
Re: no :of nodes
Eric Sosman <Eric.Sosm  2008-05-07 14:39:58 
Re: no :of nodes
Thad Smith <ThadSmith@  2008-05-07 21:03:29 
Re: no :of nodes
Keith Thompson <kst-u@  2008-05-07 21:26:12 
Re: no :of nodes
Eric Sosman <esosman@[  2008-05-08 08:36:50 
Re: no :of nodes
"Chris Thomasson&quo  2008-05-08 06:37:01 
Re: no :of nodes
Thad Smith <ThadSmith@  2008-05-16 19:30:16 
Re: no :of nodes
fred.l.kleinschmidt@[EMAI  2008-05-07 15:19:02 
Re: no :of nodes
"Chris Thomasson&quo  2008-05-07 17:14:15 
Re: no :of nodes
"Chris Thomasson&quo  2008-05-07 17:22:50 
Re: no :of nodes
cri@[EMAIL PROTECTED] (R  2008-05-08 03:02:20 
Re: no :of nodes
"Chris Thomasson&quo  2008-05-07 21:11:29 
Re: no :of nodes
cri@[EMAIL PROTECTED] (R  2008-05-08 14:41:40 
Re: no :of nodes
"Chris Thomasson&quo  2008-05-08 07:57:12 
Re: no :of nodes
Spiros Bousbouras <spi  2008-05-08 05:04:02 
Re: no :of nodes
roberson@[EMAIL PROTECTED  2008-05-08 14:53:41 
Re: no :of nodes
Spiros Bousbouras <spi  2008-05-08 08:24:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 1:14:05 CDT 2008.