If n is the total number of nodes in a complete binary tree, what is the…
2025
If n is the total number of nodes in a complete binary tree, what is the correct formula to calculate its height h?
- A.
h = ⌊log2(n)⌋
- B.
h = ⌊log2(n + 1)⌋
- C.
h = ⌊log2(n)⌋ + 1
- D.
h = ⌊log2(n - 1)⌋ + 1
Attempted by 199 students.
Show answer & explanation
Correct answer: A
The height of a complete binary tree with n nodes is given by the floor of the base-2 logarithm of n. This formula arises because each level doubles the number of nodes, so the depth corresponds to log base 2. Therefore, h equals ⌊(log2(n)⌋.