 The binary logarithm also frequently appears in the analysis of algorithms , not only because of the frequent use of binary number arithmetic in algorithms , but also because binary logarithms occur in the analysis of algorithms based on two @-@ way branching . If a problem initially has n choices for its solution , and each iteration of the algorithm reduces the number of choices by a factor of two , then the number of iterations needed to select a single choice is again the integral part of log2 n . This idea is used in the analysis of several algorithms and data structures . For example , in binary search , the size of the problem to be solved is halved with each iteration , and therefore roughly log2 n iterations are needed to obtain a problem of size 1 , which is solved easily in constant time . Similarly , a perfectly balanced binary search tree containing n elements has height log2 ( n + 1 ) − 1 . 
