算法导论[Exercises 14.2-4]

本文探讨了在红黑树节点中维护一个额外字段f的方法,该字段表示从根节点到每个节点路径上的所有a[x]值的累积运算结果。文章详细说明了如何在进行旋转操作时保持这些字段的一致性,并且展示了这些更新可以在常数时间内完成。
Exercises 14.2-4:
Start example

Let * be an associative binary operator, and let a be a field maintained in each node of a red-black tree. Suppose that we want to include in each node x an additional field f such that f[x] = a[x1] * a[x2] * ··· * a[xm], where x1, x2,..., xm is the inorder listing of nodes in the subtree rooted at x. Show that the f fields can be properly updated in O(1) time after a rotation. Modify your argument slightly to show that the size fields in order-statistic trees can be maintained in O(1) time per rotation. 

 

1)容易得到不变式 f(x) = f(left[x])*a[x]*f(right[x])]

2)在一次反转过程中,无非是a,b,r三个子树的调整,对于三个子树的f域不需要调整,因为不影响他们内部的顺序,

3)对于求B的f域, f(B) = f(b)*a[B]*f(r)

4)求A的f域f(A) = f(a)*a[A]*f(B) 

以上以left-rotate为例,right-roate类似

                       B                                                               A

               /             /                         -->                         /          /

      A                         r                                               a                  B

a            b                                                                              b                r

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值