Binary tree

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Mar 2005
Posts: 6
Reputation: acidburns is an unknown quantity at this point 
Solved Threads: 0
acidburns's Avatar
acidburns acidburns is offline Offline
Newbie Poster

Binary tree

 
0
  #1
Apr 1st, 2008
Hi everyone,
while studying binary trees, I came across this thing that a complete binary tree
has ceiling (n/2) leaves. Why is that ? and if I am to prove this through induction, what would be my base case?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,788
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 746
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Binary tree

 
0
  #2
Apr 1st, 2008
>Why is that ?
It's easiest to understand if you have a perfect binary tree (all levels are full). Notice that each branch contains twice the number of nodes. This means that in a perfect binary tree, the number of nodes on each level is exactly the number of nodes on all levels above it + 1. A perfect tree also happens to have an even number of nodes on a single level and an odd number of nodes on all levels above. If you divide the total number of nodes by 2, you get the number of internal nodes and another half (which is why ceil is needed to bump the whole result up by 1).

Now, a complete tree isn't necessarily perfect, but you can easily verify that the number of leaves will never be less than the number of internal nodes, and also never be more than 1 greater than the number of internal nodes. If the number of leaves and internal nodes are the same, the division is gives you a whole number with no fractional part, and ceil does nothing.

>if I am to prove this through induction, what would be my base case?
An empty tree with no nodes.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC