`
mybwu_com
  • 浏览: 179699 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Red Black Tree

 
阅读更多

Red-Black Tree

5 essentials :

·each node color is red or black .

·root color is black

·each leaf is black

·if parent is red color , then children are black .

·for each node ,the num of black nodes from this node to eachdecedents is same

For Insert :

1> Empty Tree

node.color = BLACK ;


2> Parent color is BLACK

do nothing

3>Parent color and uncle color are both RED

step 1:

parent.color = BLACK

uncle.color = BLACK

grantpa.color = RED



step 2:

if grantpaIS ROOT(grantpa.parent == NULL)

grantpa.color = BLACK

4>Parent color is RED and uncle color ISBLACK

4.1

parent LEFT ,new node LEFT(ST:SUB-TREE)

step 1:

parent.color = BLACK

grantPa.color = RED

step 2:

RIGHT-rotate (grantPa is center point)



4.2 parent LEFT,new node RIGHT

step 1:

Left-Route Sub-Tree


step 2:

Go to 4.1

4.3 parent RIGHT ,new nodeLEFT

step 1 :Right-rotate Sub-Tree

step 2: Goto 4.4

4.4 parentRIGHT ,new node RIGHT

step 1:

parent.color = BLACK

grantPa.color = RED

step 2: Left Rotate (grantPa is center point)



Red Black Delete :

Case 1. Delete Root

return

Case 2.Sibling.Color is Red

step 1:

S.Color= BLACK

P.Color= RED

step 2:

2.1 N Is Left Child

LEFTrotateSub-Tree (P Is center point )



Step 2.2: N Is right child

Right Rotate Sub Tree



Step 3: Go to Case 3

Case 3:

Sibling Is BLACK

Sibling left and rightchildren both BLACK

Parent is BLACK

step 1:

Set S.Color = RED

Step 2:

Go To Case 1(Parent Node)

Case 4 :Sibling color is BLACK, Sibling children are BLACK ,Parent Is RED

S.color = RED

P.color = BLACK




Case 5:

Sibling color Is BLACK

Case 5.1

Sibling LEFTChild -> RED

Sibling RIGHTChild -> BLACK

N is Parent LeftChild

Step 1:

S.color = RED

S.LEFT_Child.color = BLACK

Step 2: RIGHTRotate(S Is Center point)



step 3: Go TOCase 6(Node)

Case 5.2

Sibling LEFTChild BLACK

Sibling RIGHTChild RED

N is Parent RightChild

Step 1:

S.color = RED

S.RIGHT_Child.color = BLACK

Step 2: LEFT Rotate



Step 3: Go TO Case6(Node)

Case 6:

Case 6.1

Sibling RIGHTChild RED

Sibling LEFTChild BLACK

Node is Parent LeftChild

step 1:

s.color = parent.color

parent.color = BLACK

step 2:

s.right_Child.color = BLACK

LeftRotate(Center point is Parent)


Case 6.2:

Sibling RIGHTChild BLACK

Sibling LEFTChild RED

N is Parent RIGHTChild

step 1:

s.color = parent.color

parent.color = BLACK

step 2:

s.right_Child.color = BLACK

Left Rotate(Center point is Parent)


分享到:
评论

相关推荐

    RedBlackTree.zip

    红黑树(Red Black Tree)是一种自平衡二叉查找树,是在计算机科学中用到的一种数据结构,典型的用途是实现关联数组。 红黑树是一种特化的AVL树(平衡二叉树),都是在进行插入和删除操作时通过特定操作保持二叉树的...

    redblack tree 红黑树代码

    RedBlackTree MakeEmpty( RedBlackTree T ); Position Find( ElementType X, RedBlackTree T ); Position FindMin( RedBlackTree T ); Position FindMax( RedBlackTree T ); RedBlackTree Initialize( void ); ...

    GNU的自平衡二叉查找树(AVL tree、redblack tree等)源代码

    GNU的自平衡叉查找树的源代码库,包括AVL teee和红黑树 redblack tree、二叉查找树。还有PDF的原理说明及HTML的源代码函数解释。

    RedBlackTree-master.zip

    RedBlackTree-master基于 C 语言实现了红黑树(Red-Black Tree)以及用户测试程序。其中红黑树的实现基于二叉树、二叉排序树和平衡二叉树的接口。用户测试程序实现了初始化、销毁、插入、删除、查找、遍历、打印红黑...

    RedBlackTree.rar

    此工程主要包含红黑树的插入和删除,采用C++编写,有单独的.h和.cpp文件,方便移植

    redblacktree:golang中的自平衡二叉搜索树

    import ( "fmt" rbt "github.com/erriapo/redblacktree")func main () { t := rbt . NewTree () t . Put ( 7 , "payload7" ) t . Put ( 3 , "payload3" ) t . Put ( 1 , "payload1" ) fmt . Printf ( "size = %d \n...

    AVLTree&RedBlackTree.pptx

    介绍AVL树与红黑树,按照例子一步一图,可以对照我的博客进行理解。不明白的email durant2019@sina.com

    红黑树 RBTREE red-black-tree RBTree RED BLACK TREE

    这一版代码个人认为99.99%正确,本人使用些结构及算法用于实现嵌入式迅雷Server的任务管理。此代码经本人学习研究之后从C语言版BT源代码中的宏定义式代码中分离出来,并做成一个测试版。你也可以做一些微小的...

    redblack tree

    因为实验要求指定了输入哪些数据,所以在实现时我用了一个数组将所有的数据保存到内存里,然后直接调用插入和删除操作,这样就不再需要用户输入数据,省去了输入数据的麻烦。删除操作也是在程序里直接调用的,不要...

    red-black-tree-c.rar_red black tree_tree c语言

    红黑树的源代码,c语言版本。非常的详细。

    红黑树(Red Black Tree)

    红黑树的详细描述,从数据结构到创建,最小值,最大值,后继,遍历,插入以及删除。 该代码是clion IDE中实现的,代码全部在main.c中。

    RBT.rar_red black tree_红黑树

    运用C++进行红黑树的描述,对红黑树的插入、删除、查找等操作进行了实现等等。

    RedBlackTree:程序创建一个Red Black Tree,可以从控制台和文件添加和打印

    RedBlackTree:程序创建一个Red Black Tree,可以从控制台和文件添加和打印

    rbt.rar_rbt_red black tree_动态演示_红黑树

    红黑树的实现代码,在VC下可演示红黑树结点的动态变化.

    redblacktree_roundu2g_红黑树_

    红黑树算法的基础实现。。。。里面实现了红黑树的最基本要求

    RedBlackTree

    RedBlackTree

    RedBlackTree:使用C ++实现RedBlackTree

    这是Red-Black Tree的清晰且最小的实现。 红黑树属性 每个节点都是红色或黑色。 根和叶子(黑色)是黑色的。 如果节点为红色,则其父节点为黑色。 从任何节点X到后代叶子的所有简单路径都具有相同数量的黑色节点...

    RedBlackTree:CSC 330 红黑树

    红黑树CSC 330 RedBlackTree 自上而下实现红黑树的方法。 全面测试仍在进行中。

Global site tag (gtag.js) - Google Analytics