红黑树-结构
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

Recently, I have been going through search trees and I encountered red-black trees, the point confusing me is, In r-b tree, the root node should be black thats fine, now how will I decide whether the incoming node assumes red or black color.

I have gone through the wiki article but have not found a solution for this. I might be wrong, but I would be happy if someone can guide me through the exact material.

[Edit] That is for example, if my keys are {7, 2, 4, 1, 9, 10, 8}

Here 7 is root and it assumes black color, but what color does 2 assume? How do we decide that? And how do we decide what color the other nodes assume?

                                  7 - (Black)
                   2                              9
           1                   4        8                    10
        NIL   NIL          NIL  NIL   NIL  NIL            NIL  NIL

Do we have a random toss that decides the color of the node to be red or black. Or is it some other process.

Thank you.

#0

Look at the lecture about red-black trees on MIT open courseware.

http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/VideoLectures/

I found them to be very helpful.

Now if I remember correctly, you always insert new node as black node and then proceed to the necessary corrections (repainting and/or rotations)

#1

The incoming node must be colored RED because if you color an incoming node to be black than height of all leaf to root path for newly inserted node is going to increase by one which is going to violate RB tree property that every root to leaf path must contain equal number of black nodes.Refer this if you want more insight in insertion of RB tree http://www.youtube.com/watch?v=6QOKk_pcv3U

推荐文章

vba:未设置对象变量或带块变量

vba:未设置对象变量或带块变量

推荐文章

如何验证页面加载时在asp.net中单击了哪个链接按钮

如何验证页面加载时在asp.net中单击了哪个链接按钮

推荐文章

OpenGL:如何自动选择正确的mipmapping方法?

OpenGL:如何自动选择正确的mipmapping方法?

推荐文章

如何处理mod_wsgi/django中的阻塞IO?

如何处理mod_wsgi/django中的阻塞IO?

推荐文章

我可以重载Scala中的括号吗?

我可以重载Scala中的括号吗?

推荐文章

PLINQO主键和索引问题

PLINQO主键和索引问题

推荐文章

无法编写我想要的mysql查询

无法编写我想要的mysql查询

推荐文章

将类型化数据集从.net 2.0迁移到3.5

将类型化数据集从.net 2.0迁移到3.5

推荐文章

成员函数声明出现奇怪错误

成员函数声明出现奇怪错误

推荐文章

聚合、存储库和服务层

聚合、存储库和服务层

推荐文章

为什么VS2010调试器不在我的断点处停止?

为什么VS2010调试器不在我的断点处停止?

推荐文章

如何将除一个url以外的所有url重定向到脚本

如何将除一个url以外的所有url重定向到脚本

推荐文章

SQL服务器:没有链接服务器的链接服务器?

SQL服务器:没有链接服务器的链接服务器?

推荐文章

python:比较两个字符串

python:比较两个字符串

推荐文章

在iphone/ipad应用程序中添加加载视图的位置?

在iphone/ipad应用程序中添加加载视图的位置?

推荐文章

Blackberry开发:如何获取XMLReader SAXParser

Blackberry开发:如何获取XMLReader SAXParser