Lecture 7-8

2019-01-15  本文已影响0人  zju_dream

[toc]

Lecture 7-8

P4.Binary tree

P5.Binary search tree

P20.Tree balance

P29.Inserting

P30.Splay trees(肯定考)

threes types of rotations(题目中会给出)

[图片上传失败...(image-6fde52-1547562446283)]

P58.Red-black trees(肯定考)

  1. Every is either red or black
  2. The root and NILs are all black
  3. If a node is red, its children should be black.
  4. 每一条路径上的黑色的节点个数都相同. Every path from a node to a leaf must contain the same number of black nodes.

如果parent为黑色,直接插入即可;否则根据以下规则进行变换。

               O  grandparent
              / \
      uncle  O   O   parent
                /
              Z

新增的节点都是赋予红色的。(一次变换后,还需要进行检查)

  1. Z = root --- recolor (只有这种情况新增节点变颜色)
  2. Z.uncle = Red --- recolor(parent+grandparent+uncle)
  3. Z.uncle = Black(triangle) --- rotate parent 转到一条线上
  4. Z.uncle = Black(line) --- rotate grandparent + recolor(parent+grandparent)

suffix tree

Image3.jpg
上一篇 下一篇

猜你喜欢

热点阅读