算法架构算法设计模式和编程理论

Red-Black Tree

2017-05-18  本文已影响9人  Uchiha朵朵
  1. Root is black
  2. Leaf(NIL) is black
  3. If node is red, its children are black
  4. For each node, all simple paths from nide to descendant leaves contain the same number of black nodes.

N nodes --------> hieght : 2lg(n+1)

LEFT-ROTATE
Y = X.right
Target: 把X放到Y.left 的位置

y = x.right    x.right = y.left if y.left != T.nil       y.left.p = x       y.p = x.p if x.p == T.nil       T.root - y elseif x--x.p.left       x.p.left = y else x.p.right - y       y.left = x x.p = y

上一篇 下一篇

猜你喜欢

热点阅读