The ninth data structure, the end of ten chapters review

Chapter 9: Find

Static lookup table:

1. The order of the table lookup: sequential search

Looking forward from the rear, 0 means disposed sentinel

It is stored in the form of a sequence table or a linear list

Search algorithm of the average length = average length + the average length of time when the search is unsuccessful to find success

Find the sequence of unsuccessful length: the length of each element is unsuccessful (n + 1), that is, in fact, are relatively unsuccessful each time with a keyword (n + 1) times

The average length of the sequential search is: 3 * (n + 1) / 4

Find a sorted list: binary search

Limited to sequential storage structure, and is a sorted list

a low initial value, zero sentry means, sequence length High

Find success of the average length is:

 

 

 

3. The table lookup index order: block search

Index sequential search, also known as block search (to find an improved method of sequentially), in addition to the table itself need to create an external index table, including a key item and a pointer items.

drum

Dynamic lookup table:

Table structure itself is dynamically generated in the discovery process. For a given value of the key, if that keyword or equal to key records exist in the table, look for successful return, otherwise insert key equal to key records.

1. binary sort tree:

Binary sort tree or an empty tree; or a binary tree having the following properties:

(1) if its left subtree is not empty, then the value of the left sub-tree, all the nodes are less than the root value;

(2) if it is not empty right subtree, the right subtree of the values of all the nodes are greater than the root value;

(3) its left and right subtrees are also binary sort tree.

With binary list is stored, i.e., each node contains data about the child node pointer field

Inorder traversal of the binary sort tree can be obtained from small to large ordered sequence!

 

 

 

 2. balanced binary tree:

平衡二叉树又称AVL树,它或者是一棵空树,或者是具有下列性质的二叉树:它的左子树和右子树都是平衡二叉树,且左子树和右子树的深度之差的绝对值不超过1。

定义平衡因子:平衡因子=|左子树深度-右子树深度|《1

平均查找长度:

它的深度和log2 n是同数量级的, 由此,它的平均查找长度 也和log2 n 同数量级。

查找的时间复杂度:O(logn)

查找小窍门:

假设由于在二叉排序树上插入结点而失去平衡的最小子树根结点的指针为a,即a是离插入点最近且平衡因子绝对值超过1的祖先结点:

将离插入点最近且从0变到绝对值为1的点移到a的位置。

3.B-树:

一棵m阶的B-树,或为空树,或为满足下列特性的m叉树:

(1) 所有的非终端结点中包含下列信息数据 (n,A0,K1, A1,K2,A2,…, Kn,An) 其中:n—关键字个数(「m/2]-1<=n<=m-1). Ki(i=1,2,…,n): 关键字,且ki<ki+1(i=1,2,…,n-1); Ai(i=1,2,…,n): 指向子树根结点的指针,且指针Ai-1所指子树中所有结点的关键字均小于ki(i=1,2,…,n-1), Ai+1所指子树中所有结点的关键字均大于ki.

(2) 树中每个结点至多有m棵子树,即结点中的关键字个数<=m-1;

(3) 若根结点不是叶子结点,则至少有两棵子树;

(4) 除根之外的所有非终端结点至少有m/2(往上取)棵子树;

(5)所有的叶子结点都出现在同一层次上,并且不带信息。

B-树在文件系统中很有用,是大型数据库文件的一种组织结构。

 

 

4.B+树:

 

5.哈希表:

解决冲突的办法:

 

 

 

 

 哈希表的查找:

 用开放定址法解决冲突(即除了链地址法的冲突解决办法)

 哈希表分析:

α=n/m 值的大小(n—记录数,m—表的长度) α越大,添入表中的元素较多,产生冲突的可能性就越大;α越小,添入表中的元素较少,产生冲突的可能性就越小。

哈希表查找成功和失败的平均查找长度:

 

线性探测在散列在处理冲突的过程中易产生记录的二次聚集,而链地址法处理冲突时不会发生类似情况,故其平均查找长度较优

 

 

 查找成功有如下结果:

 

由此可知,平均查找长度跟n无关而是跟装填因子a有关。

用哈希表构造查找表时,可以选择一个适当的装填因子 a ,使得平均查找长度限定在某个范围内。

Guess you like

Origin www.cnblogs.com/xxikwonxjlxi/p/12110018.html