Reputation: 270
The formula for the number of nodes of height 'h' in an 'n' element heap is given as ceil(n/2^(h+1)). For this given problem the number of nodes of height 2 as shown in figure is 2.
But from the formula, I get ceil(19/8) = 3.
Could someone help explain my mistake?
Upvotes: 2
Views: 423
Reputation: 1874
The formula for the number of nodes of height 'h' in an 'n' element heap is given as ceil(n/2^(h+1))
Can you provide your source?
If this is regarding this problem (which I assume from your picture). It says:
A heap of size n has at most ceil(n/2^(h+1)) nodes with height h
Upvotes: 2