| | |
Binary tree
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
>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.
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.
![]() |
Similar Threads
- complete binary tree using an array help (C++)
- binary tree traversal .. (C++)
- Binary Tree Traversal (C)
- Question about binary tree & heaps (Computer Science)
- binary tree class (C++)
- C++ complete binary tree using an array. Unexpected end file (C++)
- coding a complete binary tree with Dev-C++ (C++)
Other Threads in the Computer Science Forum
- Previous Thread: how to calculate percentage of a avg marks.?
- Next Thread: Hai everybody!!!!!!!!
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware conversion csc data dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy extensions floatingpoint foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod itcontracts jobs kindle laser laws lsmeans mainframes marketing mining mobileapplication netbeans networking news os p2p piracy piratebay programming rasterizer research sas science security sex simulation software spying sql study supercomputer supercomputing sweden technology textfield turing turingtest two'scompliment uk virus warehouse ww2







