Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
360 Chapter 7: Trees Number of Levels in a Complete Binary Tree Containing N Nodes L = log 2 (N + 1) Equation 7.3 If N is such that the tree is balanced but not complete (N < nL max ), then the highest level of the tree would not be fully populated and Equation 7.3 will not yield an integer value. In this case, in order to include the highest level of the tree in the computed value of L, we use the ceiling of the previous function to determine the minimum number of levels in the tree. Thus, we have Minimum Number of Levels in a Tree Containing N Nodes (which is also the number of levels in a balanced binary tree) L = ceiling(log 2 (N + 1)) Equation 7.4 For example, a binary tree containing 600 nodes must have at least 10 levels (= ciel(log 2 (600 + 1)) = ciel(9.23) = 10), and the highest level of the tree would not be fully populated because log 2 (600 + 1) is not an integer. Armed with knowledge of tree graphics, tree terminology, and the mathematics of binary trees,