9
10
11
12
四、在一棵高度為h(h=0,1,2,…)的AVL tree 中:⑴高度為6之AVL tree 最多
可能有幾個nodes?最少可能有幾個nodes?(假設root 之h=0)(6分)
⑵假設此樹共有45個nodes。請問此AVL tree 可能最高之高度及最矮
之高度各為何?(6分)
請將下列數字{17, 60, 24, 5, 7}逐步插入圖1的AVLtree 中,並平衡之。
(12分)
圖1
五、請利用堆積排序法(Heap Sort)將圖2逐步建立成Min Heap,並將數字
從小到大逐一列舉。(10分)
圖2
六、請利用KMP(Knuth, Morris, Pratt)演算法寫出失敗函數(failure
function)之定義。(4分)
找出pattern “abcdabcabcdabcdabc”之失敗函數(failure function)值(請
填入表2 failure value 中)。(14分)
假設之pattern 嘗試在string “abcdabcabcdabcabcda…..”找出pattern。
當pattern 從index 0開始比對到index 13都一樣,而在index 14時發現
字母不一樣,請問pattern 如何利用failure function 所得之結果很快找
到下一個要對應之位置?也就是pattern 的那一位置的值要位移到
string 的那一對應位置。(4分)
表2
index
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string
a
b
c
d
a
b
c
a
b
c
d
a
b
c
a
b
c
d
a
pattern
a
b
c
d
a
b
c
a
b
c
d
a
b
c
d
a
b
c
failure value
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?