Current location - Training Enrollment Network - Mathematics courses - How does log2(3) represent rounding?
How does log2(3) represent rounding?
In data structures, rounding functions are often used to describe some values, such as rounding, rounding up and rounding down, but many people don't know their definitions and the differences between them, which leads to misunderstanding.

Considering the practical significance, only non-negative numbers are discussed here.

Integer functions are generally represented by brackets [] in mathematics, and [X] represents the largest integer not greater than x, for example, [2]=2, [2. 1]=2.

Round up, represented by the symbol ┌X┐, indicating the smallest integer not less than x. For example, ┌4.09┐=5. ┌4┐=4

Rounding down, that is, rounding off, is just a special expression in data structure. It is represented by the symbol x.

In particular, many people mistakenly think that ┌X┐-└X┘= 1, that is, the difference between rounding up and rounding down the same number is 1, which is wrong. For example, when X=6, ┌ x ┐ = ┐. Obviously, the above conclusion can only be drawn when the fractional part of x is not zero.

So some books say that the depth of a complete binary tree with n nodes is ┌log2(n)┐, which is inaccurate and should be └log2(n)┘+ 1. Of course, it is considered that the root node is located at 1 layer.