The height of a binary tree is the maximum number of edges in any root...
Maximum number of nodes will be there for a complete tree. Number of nodes in a complete tree of height h = 1 + 2 + 2^2 + 2*3 + …. 2^h = 2^(h+1) – 1
View all questions of this test
The height of a binary tree is the maximum number of edges in any root...
C)2h+1 -1
The correct answer is a) 2h-1.
Explanation:
To understand why this is the correct answer, let's consider a few examples.
Example 1: A binary tree of height 1
1
/ \
2 3
Here, the height of the tree is 1. The maximum number of nodes in any root to leaf path is 2 (root -> left child, or root -> right child). The tree has a total of 3 nodes. Let's see if the formula 2h-1 holds true:
2h-1 = 2(1)-1 = 1 (which is the correct number of nodes in this tree)
Example 2: A binary tree of height 2
1
/ \
2 3
/ \
4 5
Here, the height of the tree is 2. The maximum number of nodes in any root to leaf path is 3 (root -> left child -> left child, or root -> left child -> right child, or root -> right child). The tree has a total of 5 nodes. Let's see if the formula 2h-1 holds true:
2h-1 = 2(2)-1 = 3 (which is the correct number of nodes in this tree)
Example 3: A binary tree of height 3
1
/ \
2 3
/ \
4 5
/ \
6 7
Here, the height of the tree is 3. The maximum number of nodes in any root to leaf path is 4 (root -> left child -> left child -> left child, or root -> left child -> left child -> right child, or root -> left child -> right child -> left child, or root -> left child -> right child -> right child, or root -> right child -> left child, or root -> right child -> right child). The tree has a total of 7 nodes. Let's see if the formula 2h-1 holds true:
2h-1 = 2(3)-1 = 7 (which is the correct number of nodes in this tree)
From these examples, we can see that the formula 2h-1 gives us the correct maximum number of nodes in a binary tree of height h. Therefore, the correct answer is a) 2h-1.