Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is
    1. 2h – 1
    2. 2h – 1 – 1
    3. 2h + 1 – 1
    4. 2h + 1
Correct Option: C

This is a formula to calculate the total number of nodes. It is 2n + 1 – 1.
Let consider some examples to prove this.
1. Simplest could be taking the binary tree of h (height) = 0.
Now, the binary tree of height h will have only 1 node.

Using formula 2 ^ (0 + 1) – 1 = 1. Hence, the formula is correct.
2. Binary tree of h (height) = 2

Using formula 2 ^ (2 + 1) – 1 = 7. Hence, the formula is correct.



Your comments will be displayed only after manual approval.