二进制堆-查找高处的节点数 [英] Binary heap - Find number of nodes at a height

查看:52
本文介绍了二进制堆-查找高处的节点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了几个小时,我似乎也找不到答案.(关于Binary Heap的文章很多,但我没有这个特殊问题).

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).

问题是:

对于具有1492个节点的二进制堆,高度为2的节点数为_ 187 _.

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

我了解到,在1492个节点的情况下,二进制堆的深度为log(1492)/log(2)= 10高度2应该有2 ^(10-2)个节点,应该是256

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

为什么答案是187?

谢谢

推荐答案

以防有人需要知道.我发现公式是n/2 ^(h + 1),所以1492/2 ^(2 + 1)= 186.5.

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

这篇关于二进制堆-查找高处的节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆