Binary heap - Find number of nodes at a height

本秂侑毒 提交于 2021-01-28 03:03:57

问题


I have been struggling with this for several hours now, and I can't seem to find the answers here either. (there are many posts about Binary Heap, but I did not this particular problem).

The problem is:

For a Binary Heap with 1492 nodes, the number of nodes of height two is _187_.

I understand that with 1492 nodes, the binary heap has the depth log(1492)/log(2) = 10 height two should have 2^(10-2) nodes which should be 256

Why is the answer 187?

Thank you


回答1:


In case someone needs to know. I found out the formula is n / 2^(h+1), so 1492 / 2^(2+1) = 186.5.



来源:https://stackoverflow.com/questions/22539689/binary-heap-find-number-of-nodes-at-a-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!