
一步步用线性探测法构造哈希表,哈希函数为H(key)=key%11。
1. 逐个计算关键字的哈希地址
-23%11=1 → 地址 1-40%11=7 → 地址 7-91%11=3 → 地址 3-17%11=6 → 地址 6-19%11=8 → 地址 8-10%11=10 → 地址 10-31%11=9 → 地址 9-65%11=10 → 地址 10(冲突)-26%11=4 → 地址 4
2. 线性探测处理冲突
- 65:哈希地址 10 被 10 占用,探测下一个地址 0(空),存入地址 0。
- 其余关键字地址均无冲突,直接存入。
3. 最终哈希表
| 哈希地址 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 关键字 | 65 | 23 | 91 | 26 | 17 | 40 | 19 | 31 | 10 |
题目给的关键字序列是:23, 40, 91, 17, 19, 10, 31, 65, 26
完整计算过程(按顺序,不跳步)
- 23 →
23%11=1→ 地址 1 - 40 →
40%11=7→ 地址 7 - 91 →
91%11=3→ 地址 3 - 17 →
17%11=6→ 地址 6 - 19 →
19%11=8→ 地址 8 - 10 →
10%11=10→ 地址 10 - 31 →
31%11=9→ 地址 9 - 65 →
65%11=10→ 地址 10(冲突)→ 线性探测地址 0(空)→ 存入地址 0 - 26 →
26%11=4→ 地址 4
为什么看起来 "跳着"?
因为每个关键字的哈希地址是由哈希函数 key%11 计算出来的,不是按顺序填充的。比如:
- 第一个关键字 23 算出地址 1,不是 0;
- 第二个关键字 40 算出地址 7,不是 2;
- 第三个关键字 91 算出地址 3,不是 2;
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up