知识卡片
插入旋转次数受常数限制
红叔叔分支可能把修复点逐层上移,因此整次插入仍需 O(log n);但一旦进入旋转分支,循环结束,整次插入最多两次旋转。
比较平衡树时应区分总时间和结构改动次数。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第13章 红黑树 · 查看原书依据
Thus, RB-INSERT takes a total of O(lg n) time. Moreover, it never performs more than two rotations, since the while loop terminates if case 2 or case 3 is executed.
参考来源
- 位置:《算法导论(第4版)》第 13 章13.3 节(`OEBPS/chapter013.xhtml`,文本字符 [25000, 30000))。
- 结论依据:13.3 节分析指出只有红叔情况 1 会让 z 上移两层并重复循环;情况 2/3 执行后终止,故插入 O(log n) 且最多两次旋转。
- 原始内容:Thus, RB-I NSERT takes a total of O (lg n ) time. Moreover, it never performs more than two rotations, since the while loop terminates if case 2 or case 3 is executed.