一、二叉排序樹(二叉查找樹)
空樹或具有下列性質(zhì)的二叉樹
1.左子樹所有節(jié)點(diǎn)值小于根節(jié)點(diǎn)
2.右子樹所有節(jié)點(diǎn)大于根節(jié)點(diǎn)
3.它的左右子樹分別為二叉排序樹
二亦鳞、平衡二叉樹(AVL樹)
- 滿足二叉排序樹
- 左右子樹高度相差不超過1
三、B-樹
- 平衡
- 多路排序樹
-
主要用于文件索引
B-樹
1. 特性:
1)所有非終端節(jié)點(diǎn)包含以下信息(key-value paris)
(n康谆,A0描扯,K1,A1迅耘,K2贱枣,A2...Kn,An) **
Ki--關(guān)鍵字
Ai--指向子樹根節(jié)點(diǎn)指針
n--關(guān)鍵字個(gè)數(shù)
2)所有葉節(jié)點(diǎn)出現(xiàn)在同一層颤专,包含關(guān)鍵字 或 指向關(guān)鍵字記錄的指針
關(guān)鍵字記錄纽哥?
關(guān)鍵字key為記錄的主鍵,只是記錄的一部分栖秕。
The term leaf is also inconsistent.
Bayer & McCreight (1972) considered the leaf level to be the lowest level of keys, but Knuth considered the leaf level to be one level below the lowest keys (Folk & Zoellick 1992, p. 363).
There are many possible implementation choices.
In some designs, the leaves may hold the entire data record;
in other designs, the leaves may only hold pointers to the data record. Those choices are not fundamental to the idea of a B-tree.[5]
《數(shù)據(jù)結(jié)構(gòu)》嚴(yán)蔚敏版 此處有誤
3)樹中每個(gè)節(jié)點(diǎn)保存值
B-trees keep values in every node in the tree, and may use the same structure for all nodes.
2. B-樹查找分析
通常存儲(chǔ)在磁盤
兩步操作:
1) 找節(jié)點(diǎn)(磁盤)
磁盤隨機(jī)找到p所指節(jié)點(diǎn)春塌,并將節(jié)點(diǎn)信息讀入內(nèi)存
2) 節(jié)點(diǎn)中找關(guān)鍵字(內(nèi)存)
順序查找或折半查找關(guān)鍵字
四、B+樹
A B+ tree can be viewed as a B-tree in which each node contains only keys (not key–value pairs), and to which an additional level is added at the bottom with linked leaves.
note
12..34..567 are leaves,d1~d7 are not——they are data record.

與B-樹不同點(diǎn):
1. 所有葉子節(jié)點(diǎn)
1). 包含 全部關(guān)鍵字
2). 包含關(guān)鍵字記錄指針簇捍,如上圖12..34..567
3). 葉子節(jié)點(diǎn)升序順序鏈表鏈接
2. 非終端節(jié)點(diǎn)(即索引)只含關(guān)鍵字只壳,非B樹的關(guān)鍵字-指針對(duì)
3. 其他
- n棵子樹含n個(gè)關(guān)鍵字
- 兩指針與查找:
- root節(jié)點(diǎn)指針-->隨機(jī)查找(必須,搜索總是從root節(jié)點(diǎn)開始暑塑,代替全表掃描)
- 最小關(guān)鍵字葉子節(jié)點(diǎn)指針-->順序查找
五吼句、文件
1. 記錄2種結(jié)構(gòu)
邏輯結(jié)構(gòu)和物理結(jié)構(gòu)
2. 文件3種檢索方式
順序檢索
存取下一個(gè)邏輯記錄
直接檢索
存取第i個(gè)邏輯記錄
關(guān)鍵字檢索
查詢與關(guān)鍵字相關(guān)記錄
六、 索引文件
1. 索引表
記錄邏輯記錄和物理記錄對(duì)應(yīng)關(guān)系
索引項(xiàng)
- 定義:索引表中的項(xiàng)
- 索引項(xiàng)按關(guān)鍵字或邏輯記錄號(hào)排序
2. 索引文件
索引文件只能是==磁盤文件==
1)定義:
文件數(shù)據(jù)區(qū)+索引表
2)分類:
索引順序文件--數(shù)據(jù)區(qū)有序
索引非順序文件--數(shù)據(jù)區(qū)無序
3)索引文件檢索
兩步驟:
- 查索引表(折半)
- 查記錄(依據(jù)索引項(xiàng))
- 數(shù)據(jù)小--索引表在內(nèi)存事格,記錄在外存
- 數(shù)據(jù)大--索引惕艳、記錄均在外存