-->
当前位置:首页 > 题库 > 正文内容

主观题:Top-down Insertion for RB Tree

Luz3年前 (2022-03-02)题库739
这是一个主观题模板。请在这里写题目描述。






答案:As we move from top down, whenever we see a black node X with two red children, simply flip their colors.

If X has a red parent P, then it turns into Case 2 or 3 of the bottom-up solution, which can be solved by a simple rotation.

Why is Case 1 (X's parent's sibling is also red) impossible? Because if so, X's grandparent must have two red children, and must have been re-colored.

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。