auto commit
This commit is contained in:
@ -758,7 +758,7 @@ public class Transaction {
|
||||
|
||||
对于 N 个键,M 条链表 (N>M),如果哈希函数能够满足均匀性的条件,每条链表的大小趋向于 N/M,因此未命中的查找和插入操作所需要的比较次数为 \~N/M。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/9_200.png"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/01809172-b223-42ac-a0d1-87944fe7dc8f_200.png" width="400px"> </div><br>
|
||||
|
||||
## 3. 线性探测法
|
||||
|
||||
@ -766,7 +766,8 @@ public class Transaction {
|
||||
|
||||
使用线性探测法,数组的大小 M 应当大于键的个数 N(M>N)。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/121550407878282.gif"/> </div><br>
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/efc60f47-1d6c-4610-87d4-5db168c77b02.gif" width="400px"> </div><br>
|
||||
|
||||
```java
|
||||
public class LinearProbingHashST<Key, Value> implements UnorderedST<Key, Value> {
|
||||
@ -865,9 +866,11 @@ public void delete(Key key) {
|
||||
|
||||
#### 3.5 调整数组大小
|
||||
|
||||
线性探测法的成本取决于连续条目的长度,连续条目也叫聚簇。当聚簇很长时,在查找和插入时也需要进行很多次探测。例如下图中 2\~5 位置就是一个聚簇。
|
||||
线性探测法的成本取决于连续条目的长度,连续条目也叫聚簇。当聚簇很长时,在查找和插入时也需要进行很多次探测。例如下图中 2\~4 位置就是一个聚簇。
|
||||
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/f5cd51c9-df11-4b6a-b250-f13a9151555832287464.png" width="400px"> </div><br>
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/11_200.png"/> </div><br>
|
||||
|
||||
α = N/M,把 α 称为使用率。理论证明,当 α 小于 1/2 时探测的预计次数只在 1.5 到 2.5 之间。为了保证散列表的性能,应当调整数组的大小,使得 α 在 [1/4, 1/2] 之间。
|
||||
|
||||
|
Reference in New Issue
Block a user