当前位置:网站首页>Deng Junhui's notes on data structure and algorithm learning - Chapter 9
Deng Junhui's notes on data structure and algorithm learning - Chapter 9
2020-11-09 08:20:00 【osc_0m0d4mbq】
List of articles
day58
Chapter nine The dictionary
9. The dictionary
9.b Hash principle
Hashing- hash
The data comes from a fairly large space , But the actual data to be stored and organized is a very small subset of it , Space efficiency is extremely low
Compress space
The pigeon nest problem , take x From a larger definition domain , Mapping to a smaller range of values , There are ways to reduce conflict ( Design better hash function or increase hash table length M), But it can't be avoided ( How to solve ?)
9.c Hash function
gcd: The greatest common factor is 1
Take the middle bit , It can make the influence of each digit of the original key code closer to each other , Here's the picture , Square operations can be decomposed into addition operations
The more random the hash function is , The more irregular , The better .
key It may not be an integer , You need to convert it to hashcode, Do it again. , Here's the picture
It is necessary to , If you use a simple calculation method , It's easy to have hash conflicts
9.d Conflict
9.d1 Hash resolves conflicts 1
Skip when searching , Insert directly when inserting .
9.d2 Hash resolves conflicts 2
Closed addressing vs Open addressing
The linear heuristics described above , It's too close to each other , There will be a lot of unnecessary conflicts . You can open the space properly
Suppose the size of a cache is 1KB, Only the pointer is stored in the bucket (4 byte ), Well, unless 16 Secondary hash conflict , To make the cache invalid , Need extra I/O.
b+a≥2, yes M The nontrivial factor of , This is related to M Contradict prime numbers .
For some primes ( for example 7,11) The long table , The two-way search chain works , Some primes ( for example 5,13) The effect of the surface length is not good .
9.e bucket / Count sorting
among n Is the number of elements ,[0,M) Is the element range
Where the red line is the integral of the blue line
Linear scan over and over again count[], Scan again count[] obtain accum[], You can sort in linear time .
版权声明
本文为[osc_0m0d4mbq]所创,转载请带上原文链接,感谢
边栏推荐
- Adding OpenGL form to MFC dialog
- 你有没有想过为什么交易和退款要拆开不同的表
- Web上的分享(Share)API
- Graph node classification and message passing
- Five indispensable open source tools for me
- STS安装
- 上线1周,B.Protocal已有7000ETH资产!
- Leetcode-11: container with the most water
- How does FC game console work?
- 卧槽,这年轻人不讲武德,应届生凭“小抄”干掉5年老鸟,成功拿到字节20Koffer
猜你喜欢
结合阿里云 FC 谈谈我对 FaaS 的理解
程序员的十年之痒
GDI 及OPENGL的区别
深度优先搜索和广度优先搜索
Commodity management system -- integrate warehouse services and obtain warehouse list
Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
Introduction to nmon
Five design patterns frequently used in development
5 个我不可或缺的开源工具
Several rolling captions based on LabVIEW
随机推荐
程序员的十年之痒
Introduction to nmon
leetcode之反转字符串中的元音字母
程序员都应该知道的URI,一文帮你全面了解
Several rolling captions based on LabVIEW
Travel notes of csp-s 2020
After Android solves the setrequested orientation, the rotation of the mobile phone screen does not trigger the onconfigurationchanged method
Several common playing methods of sub database and sub table and how to solve the problem of cross database query
B. protocal has 7000eth assets in one week!
上线1周,B.Protocal已有7000ETH资产!
无法启动此程序,因为计算机中丢失 MSVCP120.dll。尝试安装该程序以解决此问题
Ten year itch of programmer
Leetcode-15: sum of three numbers
GDI 及OPENGL的区别
Combine theory with practice to understand CORS thoroughly
20201108 programming exercise exercise 3
C++邻接矩阵
Introduction to nmon
How to do thread dump analysis in Windows Environment
Concurrent linked queue: a non blocking unbounded thread safe queue