11 Hash tables
11 Hash tables
Many applications require a dynamic set that supports only the dictionary operations INSERT, SEARCH, and DELETE.
For example, a compiler that translates a programming language maintains a symbol table, in which the keys of elements are arbitrary character strings corresponding to identifiers in the language.
A hash table generalizes the simpler notion of an ordinary array. Directly ad- dressing into an ordinary array makes effective use of our ability to examine an arbitrary position in an array in O(1) time.
一个hash表是由一个简单地普通列扩展而来的。
直接寻址
使得一个普通的列
能够
检查任意位置在o(1)时间。
11.1 Direct- address tables
Direct addressing is a simple technique that works well when the universe U of keys is reasonably small.
直接寻址是一个简单地技术。
当
关键字
的区间
恰当小时,工作正常。
To represent the dynamic set, we use an array, or direct-address table, denoted by T [0.. m-1],
in which each position, or slot, corresponds to a key in the uni- verse U .
11.2 Hash tables
With direct addressing, an element with key k is stored in slot k. With hashing, this element is stored in slot h.k/; that is, we use a hash function h to compute the slot from the key k.
Here ,h maps the universe U of keys into the slots of a hash table T[0.. m-1]:
h:U->{0,1,…,m-1}
We say that an element with key k hashes to slot h.k/; we also say that h.k/ is the hash value of key k.

There is one hitch: two keys may hash to the same slot. We call this situation a collision.
Collision resolution by chaining

In chaining, we place all the elements that hash to the same slot into the same linked list
The dictionary operations on a hash table T are easy to implement when collisions are resolved by chaining 
11.3 Hash functions
In this section ,we discuss some issues regrading the design of good hash functions and then present three schemes for their creation . Two of the schemes ,hashing by division and hashing by multiplication ,are heuristic in nature ,whereas the third scheme ,universal hashing ,uses randommization to provide provably good performance .
11.3.1 The division method
h(k)=k mod m
11.3.2 The multiplication method
The multiplication method for creating hash functions operates in two steps. First, we multiply the key k by a constant A in the range 0 < A < 1 and extract the
fractional part of kA. Then, we multiply this value by m and take the floor of the result. In short, the hash function is

这两个函数是最简单的。
hash表最重要的就是找到一个哈希函数,让其尽量的避免或少点collision。
11.4 Open addressing
In open addressing ,all elements occupy the hash table itself . That is ,each table entry contains either an element of the dynamic set or nil.When searching for an element, we systematically examine table slots until either we find the desired element or we have ascertained that the element is not in the table. No lists and
no elements are stored outside the table, unlike in chaining.
The advantage of open addressing is that it avoids pointers altogether .
开放地址的好处是完全避免了指针。
Instead of following pointers, we compute the sequence of slots to be examined.
代替指针的是我们计算slots 的序列来检查。
The hash function becomes :

With open addressing ,we require that for every key k, the probe sequence 
be a permutation of <0,1,,..m-1>
The algorithm for searching for key k probes the same sequence of slots that the insertion algorithm examined when key k was inserted.

In our analysis ,we assume uniform hashing : the probe sequence of each key is equally likely to be any of the m!permutations of <0,1,2,m-1>.
We will examine three commonly used techniques to compute the probe sequences required for open addressing : linear probing ,quadratic probing ,and double hashing .
线性探针,平方探针,双重探针。
Linear probing
Given an ordinary hash function h':u->{0,1,m-1} ,which we refer to as an auxiliary hash function ,the method of linear probing uses the hash function 

Double hashing
Double hashing offers one of the best methods available for open addressing be- cause the permutations produced have many of the characteristics of randomly chosen permutations. Double hashing uses a hash function of the form

11 Hash tables的更多相关文章
- Hash Tables
哈希表 红黑树实现的符号表可以保证对数级别的性能,但我们可以做得更好.哈希表实现的符号表提供了新的数据访问方式,插入和搜索操作可以在常数时间内完成(不支持和顺序有关的操作).所以,在很多情况下的简单符 ...
- 数据库(11)-- Hash索引和BTree索引 的区别
索引是帮助mysql获取数据的数据结构.最常见的索引是Btree索引和Hash索引. 不同的引擎对于索引有不同的支持:Innodb和MyISAM默认的索引是Btree索引:而Mermory默认的索引是 ...
- Hash Tables and Hash Functions
Reference: Compuer science Introduction: This computer science video describes the fundamental princ ...
- Javascript: hash tables in javascript
/** * Copyright 2010 Tim Down. * * Licensed under the Apache License, Version 2.0 (the "License ...
- Hash Table Performance in R: Part I(转)
What Is It? A hash table, or associative array, is a well known key-value data structure. In R there ...
- Effective Java 第三版——11. 重写equals方法时同时也要重写hashcode方法
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- 06: 字典、顺序表、列表、hash树 实现原理
算法其他篇 目录: 1.1 python中字典对象实现原理 1.2 顺序表 1.3 python 列表(list) 1.1 python中字典对象实现原理返回顶部 注:字典类型是Python中最常 ...
- NoSQL生态系统——hash分片和范围分片两种分片
13.4 横向扩展带来性能提升 很多NoSQL系统都是基于键值模型的,因此其查询条件也基本上是基于键值的查询,基本不会有对整个数据进行查询的时候.由于基本上所有的查询操作都是基本键值形式的,因此分片通 ...
- hash算法总结收集
hash算法的意义在于提供了一种快速存取数据的方法,它用一种算法建立键值与真实值之间的对应关系,(每一个真实值只能有一个键值,但是一个键值可以对应多个真实值),这样可以快速在数组等条件中里面存取数据. ...
随机推荐
- 辛星浅析一次ajax的实现过程
说到ajax,那绝对是一个老生常谈的话题,近些年ajax技术的使用颇为盛行. 以下我们就以jQuery为例来从一个真实的项目中看一下ajax的实例. 首先是前端页面,这个页面我们使用的是bootstr ...
- myeclipse提示:Syntax error on tokens, delete these tokens怎么解决
有中文字符或者符号,包括空格. 上次遇到一个问题,检查了一遍语法没错误, 后来发现是拷贝代码的时候有一部分中文空格没删除,就出现这个问题了. 一个个删除就OK了.
- 如何用DOS命令,获取一个目录下的文件数目
发信人: GOOGOODALLS (我爱Figo), 信区: DOS 标 题: 如何用DOS命令,获取一个目录下的文件数目? 发信站: 水木社区 (Fri Mar 9 08:40:01 2007) ...
- linux输入yum后提示: -bash: /usr/bin/yum: No such file or directory的解决方案
linux输入yum后提示: -bash: /usr/bin/yum: No such file or directory的解决方案 今天在安装程序时,发现有一个插件未安装,我就随手敲了一个命令,看都 ...
- pymssql.connect(server='.', user='', password='', database='', timeout=0, login_timeout=60, charset='UTF-8', as_dict=False, host='', appname=None, port='1433', conn_properties, autocommit=False, tds_
http://pymssql.org/en/stable/ref/pymssql.html """ This is an effort to convert the py ...
- IT江湖--这个冬天注定横尸遍野(多数人技术迟迟无进阶,多半是懒的原因。勤是必须的)
今年江湖大事繁起,又至寒冬,冻的不仅是温度,更是人心. 这两天上班途中看到多个公众号和媒体发了很多 "XXX公司裁员50%" 等等诸如此类的文章,也真是撼动人心.寒冬,比以往来的更 ...
- ABAP 创建和调用WebService
1.创建WebService ① SE37创建RFC函数 ② SE80创建企业服务-service provider-existing ABAP object 或SE37-实用程序-创建Web服务 ③ ...
- 设计模式-(7)桥接(swift版)
一,概念 桥接模式为把抽象层次结构从实现中分离出来,使其可以独立变更,抽象层定义了供客户端使用的上层抽象接口,实现层次结构定义了供抽象层次使用的底层接口,实现类的引用被封装于抽象层的实例中,桥接就形成 ...
- 揭开自然拼读法(Phonics)的神秘面纱
揭开自然拼读法(Phonics)的神秘面纱 自然拼读法 (Phonics),是指看到一个单词,就可以根据英文字母在单词里的发音规律把这个单词读出来的一种方法.即从“字母发音-字母组合发音-单词-简单 ...
- 函数,#include <>和#include " "区别
l 4..函数定义到使用分三步:1.声明.2.定义函数.3.调用函数. 2.函数的定义格式:返回值 函数名(形参列表){ 函数体; return } 命名规则:1.只能由字母.数字.下划线或者美元符号 ...