Reference: Compuer science

Introduction:

This computer science video describes the fundamental principles of the hash table data structure which allows for very fast insertion and retrieval of data. It covers commonly used hash algorithms for numeric and alphanumeric keys and summarises the objectives of a good hash function. Collision resolution is described, including open addressing techniques such as linear and quadratic probing, and closed addressing techniques such as chaining with a linked list.

Consider a list:

Find Ada

You can use linearly search, which costs the time of O(n)

Or you happend to know the index of ada(8), you can look up the value very quickly.

this costs you the time of O(1)

Can help wondering that what if we encode the name into index would the look-up process become O(1).?

Absolutely!

we can turn the key(i.e. the name) into a number(index) with a hash function.

Let's say take each letter of the word get its ascii code,add them up,divided by the length of the array,get the remainder.

Namely , the hash function here is :

we can serve the properties of a person as the value,the name as key.

So that we can look up the profile of a person by the key(i.e.name)

Notes:

So far you aquire the ability to transform a key into index, you can look up very information by hash table.

Needless to say, that is unrealistic.

Have you ever consider the case that two different key are truned into a same index number?

That is collisions.

Let's look a example.

How to solve collisions?

we can put sue into  the next place index5 which is empty.

Basically we can put the one that causes collision into the next empty place.

this is linear probing.

put the element somewhere other than the caculated adress is call  open adressing.

because every location is open to every elements.

we can use a varity of techniques to decide where to palce.

If we get to the end of the array still can't  find a empty place,

it may cycle around to the start of the array.

As you can image , the indexing process is also involved linear probing.(linear search)

In the worse case scenario, it takes O(n) to store and search a key.

Need to mention:

Another way  to deal with collisions is called chaining. (close addressing)

we add a linked list in the collision index.

traverse the linked list also takes time.

Summary:

Hash Tables and Hash Functions的更多相关文章

  1. 11 Hash tables

    11 Hash tables    Many applications require a dynamic set that supports only the dictionary operatio ...

  2. 查询计划Hash和查询Hash

    查询计划hash和查询hash 在SQL Server 2008中引入的围绕执行计划和缓冲的新功能被称为查询计划hash和查询hash.这是使用针对查询或查询计划的算法来生成二进制hash值的二进制对 ...

  3. 14.4.3 Adaptive Hash Index 自适应hash index

    14.4.3 Adaptive Hash Index 自适应hash index 自适应hash index(AHI) 让InnoDB 执行更像内存数据库在系统使用合适的负载组合和足够的内存用于Buf ...

  4. 14.2.5.6 Adaptive Hash Indexes 自适应Hash Indexes

    14.2.5.6 Adaptive Hash Indexes 自适应Hash Indexes adaptive hash index(AHI) 让InnoDB 执行更加像在一个内存数据库里在, 在不牺 ...

  5. Hash::make与Hash::check

    调用方法之前要先去引用: use Illuminate\Support\Facades\Hash; 可以调用 Hash 门面上的 make 方法对存储密码进行哈希: $pwd = Hash::make ...

  6. 转载:字符串hash总结(hash是一门优雅的暴力!)

    转载自:远航休息栈 字符串Hash总结 Hash是什么意思呢?某度翻译告诉我们: hash 英[hæʃ] 美[hæʃ]n. 剁碎的食物; #号; 蔬菜肉丁;vt. 把…弄乱; 切碎; 反复推敲; 搞糟 ...

  7. cdoj1092-韩爷的梦 (字符串hash)【hash】

    http://acm.uestc.edu.cn/#/problem/show/1092 韩爷的梦 Time Limit: 200/100MS (Java/Others)     Memory Limi ...

  8. Hash表及hash算法的分析

    Hash表中的一些原理/概念,及根据这些原理/概念: 一.       Hash表概念 二.       Hash构造函数的方法,及适用范围 三.       Hash处理冲突方法,各自特征 四.   ...

  9. Cuckoo Hash和多级Hash的粗浅认识

    通过对Cuckoo Hash.多级Hash和BloomFilter的粗浅了解,感觉它们三者存在类似之处,算是近亲(暂且把普通的Hash称作远亲). Cuckoo Hash的思想非常简单,冲突时,重Ha ...

随机推荐

  1. 学习笔记:斜率优化DP

    作为数学渣,先复习一下已知两点\((x_1, y_1)\), \((x_2, y_2)\),怎么求过两点的一次函数的斜率... 待定系数法代入 \(y = kx + b\) 有: \(x_1k + b ...

  2. P4085 [USACO17DEC]Haybale Feast

    我又开始水了,感觉又是一道虚假的蓝题 题意 非常好理解,自己看吧 题解 可以比较轻易的发现,如果对于一段满足和大于等于 \(m\) 的区间和其满足和大于等于 \(m\) 的子区间来说,选择子区间肯定是 ...

  3. Jmeter(3)返回内容乱码

    一.创建jmeter实例测试百度接口返回 1.添加线程组 2.添加取样器 3.添加监听器 二.运行结果如下 返回结果中有乱码,原因是Jmeter取样器结果的编码默认为sampleresult.defa ...

  4. oracle 11g修改归档日志目录及大小

    1.查看当前归档日志目录 SQL> show parameter recovery NAME TYPE VALUE ------------------------------------ -- ...

  5. ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)

    警告日志中发现如下报错信息: ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)ORA-01110: data file 3 ...

  6. Jmeter对数据库做压力测试

    一.环境:apache-jmeter-5.0,Oracle11g.windows7.jdk1.8.ojdbc14-10.2.0.2.0.jar二.操作配置:2.1.启动Jmeter Jmeter初始化 ...

  7. 记一次 HBase Master is initializing 问题处理

    问题 hbase shell中建立建表出错 分析 org.apache.hadoop.hbase.PleaseHoldException: Master is initializing代表Master ...

  8. 01-docker基本使用

    docker 常用命令 指令 说明 docker images 查看已经下载的镜像 docker rmi 镜像名称:标签名 删除已经下载的镜像 docker search 镜像 从官方仓库中查看镜像 ...

  9. [日常摸鱼]loj6000「网络流 24 题」搭配飞行员

    题面 应该是二分图匹配,不过我写的是网络最大流. dinic求二分图最大匹配:加个源点和汇点,源点连向二分图的一边所有点,二分图的另一边所有点连向汇点,很明显这样得到的最大流就是这个二分图的最大匹配. ...

  10. APP端有原生态的控件,但嵌入了H5页面,怎么定位到H5页面的元素

    appium 通常有很多种定位元素方法,例如xpath,driver.find_element_by_accessibility_id等,安卓sdk自带的uiautomatorviewer但是对于H5 ...