Blessen George
Blessen George

Reputation: 270

Number of nodes of given height 'h' in an n element heap inconsistency

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. enter image description here

But from the formula, I get ceil(19/8) = 3.

Could someone help explain my mistake?

Upvotes: 2

Views: 423

Answers (1)

Ajk_P
Ajk_P

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

Related Questions