<数据结构>笔记1-【B树和索引】

2017-04-07  本文已影响90人  PennLi

一、二叉排序树(二叉查找树)

空树或具有下列性质的二叉树
1.左子树所有节点值小于根节点
2.右子树所有节点大于根节点
3.它的左右子树分别为二叉排序树

二、平衡二叉树(AVL树)

三、B-树

1. 特性:

1)所有非终端节点包含以下信息(key-value paris)

(n,A0,K1,A1,K2,A2...Kn,An) **
Ki--关键字
Ai--指向子树根节点指针
n--关键字个数

2)所有叶节点出现在同一层,包含关键字 或 指向关键字记录的指针

关键字记录?

关键字key为记录的主键,只是记录的一部分。

wikipedia for B-tree

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]

《数据结构》严蔚敏版 此处有误

3)树中每个节点保存值

B-trees keep values in every node in the tree, and may use the same structure for all nodes.

2. B-树查找分析

通常存储在磁盘

两步操作:

1) 找节点(磁盘)

磁盘随机找到p所指节点,并将节点信息读入内存

2) 节点中找关键字(内存)

顺序查找或折半查找关键字

四、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.

2. 文件3种检索方式

顺序检索

存取下一个逻辑记录

直接检索

存取第i个逻辑记录

关键字检索

查询与关键字相关记录

六、 索引文件

1. 索引表

记录逻辑记录物理记录对应关系

索引项

2. 索引文件

索引文件只能是==磁盘文件==

1)定义:

文件数据区+索引表

2)分类:

索引顺序文件--数据区有序
索引非顺序文件--数据区无序

3)索引文件检索

两步骤:

  1. 索引表(折半)
  2. 查记录(依据索引项)
上一篇 下一篇

猜你喜欢

热点阅读