how to find the number of nodes in a binary tree when given maximum size is 5
Answers
Answered by
0
The height of the binary tree is the longest path from root node to any leaf node in the tree. For example, the height of binary tree shown in Figure 1(b) is 2 as longest path from root node to node 2 is 2. Also, the height of binary tree shown in Figure 1(a) is 4.
Binary Tree –
In a binary tree, a node can have maximum two children.
Calculating minimum and maximum height from number of nodes –
If there are n nodes in binary tree, maximum height of the binary tree is n-1 and minimum height is floor(log2n).
For example, left skewed binary tree shown in Figure 1(a) with 5 nodes has height 5-1 = 4 and binary tree shown in Figure 1(b) with 5 nodes has height floor(log25) = 2.
Binary Tree –
In a binary tree, a node can have maximum two children.
Calculating minimum and maximum height from number of nodes –
If there are n nodes in binary tree, maximum height of the binary tree is n-1 and minimum height is floor(log2n).
For example, left skewed binary tree shown in Figure 1(a) with 5 nodes has height 5-1 = 4 and binary tree shown in Figure 1(b) with 5 nodes has height floor(log25) = 2.
Similar questions
English,
7 months ago
Physics,
7 months ago
Social Sciences,
1 year ago
Biology,
1 year ago
History,
1 year ago
Social Sciences,
1 year ago