阵列重新最小 - 堆presentation [英] Array representation of a min-heap

查看:124
本文介绍了阵列重新最小 - 堆presentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果阵列是具有20(0-19)的尺寸和的映射是从第(i-1)/ 2至母体。什么的第(i-1)的映射/ 2意味着相对于重新presenting最小 - 堆13的尺寸的

If an array is has a size of 20 (0-19) and the mapping is from (i-1)/2 to a parent. What does mapping of (i-1)/2 mean in relation to representing a min-heap of a size of 13?

推荐答案

正如丹所述的映射是所述阵列的同一任何大小。如果有帮助,这里是二叉堆树为你提供的例子,与第二个70(3级)更改为71 二进制堆树

As Dan said the mapping is the same whatever the size of the array. If it helps, here is the binary heap tree for the example you provided, with the second 70 (in level 3) changed to 71.

您可以通过遍历树自上而下获得二进制堆阵,左到右。下面是结果数组如下所示的指数,这样你就可以映射很容易应用到一个索引,看看那里发生什么样的价值和交叉检查与树再现。

You can get the binary heap array by traversing the tree top-down, left-to-right. Below is the resulting array with the indices shown below, so you can easily apply the mapping to an index and see what value occurs there and cross check with the tree rendition.

array  :  10 | 20 | 25 | 60 |  30 | 58 | 71 | 99 | 70 |  82 | 50 | 90 | 85
indices:   0 |  1 |  2 |  3 |   4 |  5 |  6 |  7 |  8 |   9 | 10 | 11 | 12 

我希望这清除了你的疑惑。

I hope this clears up your doubts.

这篇关于阵列重新最小 - 堆presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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