当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
- Sublime text3 插件ColorPicker(调色板)不能使用快捷键的解决方法
- Get the first cover image of video through canvas
- 理论与实践相结合彻底理解CORS
- 老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”
- leetcode之反转字符串中的元音字母
- 服务器性能监控神器nmon使用介绍
- 1. What does the operating system do?
- Copy on write collection -- copyonwritearraylist
- B. protocal has 7000eth assets in one week!
猜你喜欢

Windows环境下如何进行线程Dump分析

linx7.5 初始安装

A few lines of code can easily transfer traceid across systems, so you don't have to worry about losing the log!

Android emulator error: x86 emulation currently requires hardware acceleration solution

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

Installation record of SAP s / 4hana 2020

第五章编程

EasyNTS上云网关设备在雪亮工程项目中的实战应用

Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法

Concurrent linked queue: a non blocking unbounded thread safe queue
随机推荐
结合阿里云 FC 谈谈我对 FaaS 的理解
android开发中提示:requires permission android.permission write_settings解决方法
Web上的分享(Share)API
Commodity management system -- the search function of SPU
Programmers should know the URI, a comprehensive understanding of the article
C++之异常捕获和处理
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
首次开通csdn,这篇文章送给过去的自己和正在发生的你
对象
API部分的知识点复习
5 个我不可或缺的开源工具
Combine theory with practice to understand CORS thoroughly
A solution to the problem that color picker (palette) cannot use shortcut keys in sublime Text3 plug-in
Installation record of SAP s / 4hana 2020
linx7.5 初始安装
Common feature pyramid network FPN and its variants
B. protocal has 7000eth assets in one week!
OSChina 周一乱弹 —— 程序媛的青春
操作系统之bios
centos7下安装iperf时出现 make: *** No targets specified and no makefile found. Stop.的解决方案