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: K&R2, Binar...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 9 Topic 26157 of 27679
Post > Topic >>

Re: K&R2, Binary-Tree, section 6.5

by Ben Pfaff <blp@[EMAIL PROTECTED] > May 12, 2008 at 09:17 AM

arnuld <sunrise@[EMAIL PROTECTED]
> writes:

>                    now
>                 /       \
>               is         the
>             /   \       /   \
>          for    men    of    time
>         /   \           \    /    \
>      all   good      party  their  to
>     /   \
>   aid   come
>
>
>
> This is an unbalanced-tree, where balanced factor is:
>
>   (1 - 3)  = -2
>
> balance factor = (height of right-subtree) - (height of left-subtree)

I don't see how you get a balance factor of -2 from that tree.  I
see a balance factor of -1:

                             now
                          /       \
        ^               is         the           ^
        |             /   \       /   \          |
height  |          for    men    of    time      |  height
  4     |         /   \           \    /    \    |    3
        |      all   good      party  their  to  V
        |     /   \
        V   aid   come

The right child of "now" has height 3.  The left child of "now"
has height 4.  The difference is -1.

> right-subtree starts with word "the" which has only 1 child-node.

"the" has two children: "of" and "time".

> left-subtree starts with "is" and it has 3 nodes

"is" also has two children: "for" and "men".
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long
b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return
0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case
1:putchar(a[i&15]);break;}}}
 




 9 Posts in Topic:
K&R2, Binary-Tree, section 6.5
arnuld <sunrise@[EMAIL  2008-05-12 11:44:18 
Re: K&R2, Binary-Tree, section 6.5
arnuld <sunrise@[EMAIL  2008-05-12 12:49:00 
Re: K&R2, Binary-Tree, section 6.5
Ben Pfaff <blp@[EMAIL   2008-05-12 09:17:46 
Re: K&R2, Binary-Tree, section 6.5
arnuld <sunrise@[EMAIL  2008-05-13 21:13:11 
Re: K&R2, Binary-Tree, section 6.5
Ben Pfaff <blp@[EMAIL   2008-05-13 10:15:01 
Re: K&R2, Binary-Tree, section 6.5
arnuld <sunrise@[EMAIL  2008-05-15 10:28:52 
Re: K&R2, Binary-Tree, section 6.5
Ben Pfaff <blp@[EMAIL   2008-05-15 08:37:23 
Re: K&R2, Binary-Tree, section 6.5
arnuld <sunrise@[EMAIL  2008-05-13 21:15:23 
Re: K&R2, Binary-Tree, section 6.5
Richard Heathfield <rj  2008-05-13 05:08:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Oct 11 21:22:41 CDT 2008.