[toc]
Lecture 7-8
P4.Binary tree
- 二叉樹的基本操作
P5.Binary search tree
- 什么是balance search tree、大小關系、給出一個不平衡的->平衡
- 練習題:p28
P20.Tree balance
- 如何判斷一棵樹是否平衡
- We say that a binary tree is balanced if the height difference between the right and left subtree of all its nodes is not greater than one.
P29.Inserting
- 要會操作
P30.Splay trees(肯定考)
- 考步驟、會插入刪除
threes types of rotations(題目中會給出)
[圖片上傳失敗...(image-6fde52-1547562446283)]
- 在zig-zig中先轉哪個得先看清楚
P58.Red-black trees(肯定考)
- 掌握四條定義、會判斷是否是紅黑樹
- Every is either red or black
- The root and NILs are all black
- If a node is red, its children should be black.
- 每一條路徑上的黑色的節點個數都相同. Every path from a node to a leaf must contain the same number of black nodes.
如果parent為黑色,直接插入即可;否則根據以下規則進行變換。
O grandparent
/ \
uncle O O parent
/
Z
新增的節點都是賦予紅色的。(一次變換后,還需要進行檢查)
- Z = root --- recolor (只有這種情況新增節點變顏色)
- Z.uncle = Red --- recolor(parent+grandparent+uncle)
- Z.uncle = Black(triangle) --- rotate parent 轉到一條線上
- Z.uncle = Black(line) --- rotate grandparent + recolor(parent+grandparent)
suffix tree
-
suffix 有很多
- s = abaaba$
- $
- a$
- ba$
- aba$
- aaba$
- baaba$
- abaaba$
- s = abaaba$
-
suffix trie 樹
- 可以得到三個信息
- 有沒有
- 有幾個
-
分別從哪邊開始
Image.jpg
- 可以得到三個信息
- 兩個字符串判斷公共的子串
- 分別先往子串后面加上符號
-
最后標上每一層X or Y or XY,找XY層數最多的,字符最長的,把邊讀出來就是最長子串
Image2.jpg
Image3.jpg