当前位置:网站首页>哈希表、无序集合、映射的原理与实现
哈希表、无序集合、映射的原理与实现
2022-07-23 20:02:00 【Adobee Chen】
哈希表(Hash table)又称散列表,是一种可以通过key直接进行访问的数据结构。
哈希表由两部分组成
- 一个数据结构,通常是链表、数组
- Hash函数,输入key返回数据结构的索引
例子:
hash_table["lies"]=233的例子,以各ASCII码相加mod20为Hash函数

如果其他的key经过hash函数计算也是放在9的位置,那么就会发生hash碰撞。
hash碰撞指的是两个不同的key被计算出同样的Hash结果,把复杂信息映射到小的值域,发生碰撞是不可避免的,好的Hash函数可以减少碰撞发生的机率,让数据尽可能的均衡分布
开散列是最常见的碰撞解决方案
- Hash函数依然用于计算数组下标
- 数组的每个位置存储一个链表的表头指针(我们称它为表头数组)
- 每个链表保存具有同样Hash值得数据
时间复杂度
期望:插入、查询、删除 O(1) ---------数据分布比较均匀时
最坏:插入、查询、删除O(N)-----------数据全部都被映射为相同得Hash值时
集合与映射
集合(set)存储不重复得元素
- 有序集合,便利时按元素大小排序,一般用平衡二叉搜索树实现,O(logN)
- 无序集合,一般用hash实现,O(1)
映射(map) 存储关键码(key)不重复的键值对(key-value pair)
- 有序映射,遍历时按照key大小排序,一般用平衡二叉搜索树实现,O(logN)
- 无序映射,一般用哈希表实现,O(1)
对于语言内置的类型(int,string),已经有默认的优秀的hash函数,可以直接放进set/map里使用
边栏推荐
- 21.mixin混入详解
- Adobe Acrobat两个强大的插件
- 【Jailhouse 文章】A Novel Software Architecture for Mixed Criticality Systems(2020)
- 2022/7/22 训练日志
- The latest version of conflict+docker+mysql8 deployment tutorial
- How to add to-do items for win11 widgets? Win11 method of adding to-do widget
- What if there is no word document in win11? There is no word document solution tutorial in win11
- Dokcer image understanding
- 【AR学习】-- 二、 环境搭建
- 2022山东养老展,中国国际养老服务业展览会,济南老龄产业展
猜你喜欢

小程序頭像組樣式

osgearth2.8编译siverlining云效果

scanf()和getchar()的用法讨论

shell命令及运行原理

138-查询案例-涉及知识点:forEach遍历&computed计算属性&v-for循环

Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 6

Uncover the working principle of solid state disk

Leetcode 228. summary interval (yes, solved)

Solve the problem that the user clicks quickly and repeats the request within 1 second

21.mixin混入详解
随机推荐
next数值型数据类型()出现输入错误后,下次依然能正常输入
Uncover the working principle of solid state disk
OneFlow v0.8.0正式发布
Leetcode 152. product maximum subarray (brute force cracking can actually pass!)
Failure after reinstalling the system (error: Reboot and select proper boot device or insert boot media in selected boot device)
Reduced order method of linear algebraic determinant calculation method
多子系统多业务模块的复杂数据处理——基于指令集物联网操作系统的项目开发实践
最新版Confluence+Docker+MySQL8部署教程
ODrive应用 #6 编码器
QT with OpenGL (frame cache)
源启数字化:既有模式,还是开源创新?|砺夏行动
osgearth使用sundog公司的triton海洋和silverlining云彩效果
数组——704. 二分查找
What antenna is used for ant interface_ There is an interface at the back of the TV that says standard ant 75 Euro input. What does it mean, antenna? Can you connect the closed route "Suggested collec
shell脚本中$#、$*、[email protected]、$?、$0等含义一文搞懂
安装Win11找不到固态硬盘如何解决?
LyScriptTools 扩展Script模块
【C语言】通讯录(静态版本)
TASK03|回归
【力扣】最接近的三数之和