Now I do not give mathematical proofs. Try to understand the problem using a log for base 2. Log 2 is the normal value of a log in computer science.
First you need to understand the binary logarithm (log
2 n) (the logarithm to base 2). For example,
- the binary logarithm of 1 is 0
- the binary logarithm of 2 is 1
- the binary logarithm of 3 is 1
- the binary logarithm of 4 is 2
- the binary logarithm of 5, 6, 7 is 2
- the binary logarithm of 8-15 is 3
- the binary logarithm of 16-31 is 4, etc.
For each height, the number of nodes in a fully balanced tree
Height Nodes Log calculation
0 1 log 2 1 = 0
1 3 log 2 3 = 1
2 7 log 2 7 = 2
3 15 log 2 15 = 3
Consider a balanced tree between 8 and 15 nodes (any number, say, 10). It will always be height 3 because log 2 of any number from 8 to 15 is 3.
In a balanced binary tree, the size of the problem to be solved is halved with each iteration. Thus, coarse log 2 n iterations are needed to get a size 1 problem.
Hope this helps.
Sandesh kobal
source share