算法4习题 2.4.10

Page content

2.4.10

问题:

2.4.10 Suppose that we wish to avoid wasting one position in a heap-ordered array pq[], putting the largest value in pq[0], its children in pq[1] and pq[2], and so forth, proceeding in level order. Where are the parents and children of pq[k]?

分析:

答案:

子节点:$ 2k+1, 2k+2 $,父节点: $ \lfloor \frac{k-1}{2} \rfloor $

参考: