当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Chapter 5 programming
- Application of cloud gateway equipment on easynts in Xueliang project
- 通过canvas获取视频第一帧封面图
- Windows环境下如何进行线程Dump分析
- 梁老师小课堂|谈谈模板方法模式
- How to reduce the resource consumption of istio agent through sidecar custom resource
- Copy on write collection -- copyonwritearraylist
- File queue in Bifrost (1)
- 重新开始学习离散数学
- 1.操作系统是干什么的?
猜你喜欢

Sublime text3 插件ColorPicker(调色板)不能使用快捷键的解决方法

Several common playing methods of sub database and sub table and how to solve the problem of cross database query

How to reduce the resource consumption of istio agent through sidecar custom resource

结合阿里云 FC 谈谈我对 FaaS 的理解

Depth first search and breadth first search

Graph node classification and message passing

android开发中提示:requires permission android.permission write_settings解决方法

Web上的分享(Share)API

LTM理解及配置笔记记录

OpenGL ES 框架详细解析(八) —— OpenGL ES 设计指南
随机推荐
Bifrost 之 文件队列(一)
分库分表的几种常见玩法及如何解决跨库查询等问题
How to get started with rabbitmq
[Python from zero to one] 5. Detailed explanation of beautiful soup basic syntax of web crawler
Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
Graph node classification and message passing
The difference between GDI and OpenGL
Windows环境下如何进行线程Dump分析
Commodity management system -- the search function of SPU
Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
2020,Android开发者打破寒冬的利器是什么?
23张图,带你入门推荐系统
Save code
BIOS of operating system
使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
LeetCode-15:三数之和
Introduction to nmon
《MFC dialog中加入OpenGL窗体》
上线1周,B.Protocal已有7000ETH资产!
程序员都应该知道的URI,一文帮你全面了解