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. 零基础的Java小白如何准备初级开发的面试

    对于各位Java程序员来说,只要能有实践的机会,哪怕工资再低,公司情况再一般,只要自己上心努力,就可能在短时间内快速提升,甚至在工作2年后进大厂都有希望,因为项目里真实的开发实践环境是平时学习不能模拟 ...

  2. 5+App 相关记录

    一.页面跳转到app 1.应用的manifest.json文件,plus --> distribute --> google 节点下,增加属性 schemes 2.打包后,在手机里安装. ...

  3. 查找列表中的元素,移动空格 并查找以a或A 为开头 并以c 结尾的元素

    li = ['alec',' aric','Alex','Tony','rain']tu = ('alec',' aric','Alex','Tony','rain')dic = { 'k1':'al ...

  4. 【面试专栏】ArrayList 非线程安全案例并提供三种解决方案

    1. 复现问题 import java.util.ArrayList; import java.util.List; import java.util.UUID; /** * 复现问题 * * @au ...

  5. Service Cloud 零基础(二)Knowledge浅谈

    本篇参考:https://trailhead.salesforce.com/content/learn/projects/set-up-salesforce-knowledge https://tra ...

  6. bp VNext 入门——让ABP跑起来

    因好多群友@我说,ABP他们简单的了解了下,按照官方的教程一路下来跑不起来(倒在了入门的门口),才有了此文. 此文结合官方文档,一步一步带领大家让ABP跑起来(跨过门口). 建议大家一步一步实际动手操 ...

  7. Wordpress Polylang 翻译自定义格式

    WordPress 多语言插件 Polylang 主题函数参考 重要:使用一个函数之前,你必须检查函数是否存在,否则,你的网站可能会在 Polylang 更新之前遇到致命错误(因为 WordPress ...

  8. Kubernetes K8S之Helm部署、使用与示例

    Kubernetes K8S之Helm部署.使用.常见操作与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7.7 2 ...

  9. PHP比较数组、对象是否为空

    PHP简单对比对象.数组是不是为空: 1 <?php 2 /*简单的比较对象和数组是不是为空*/ 3 4 #定义空类EmptyClass 5 class EmptyClass{} 6 7 $em ...

  10. WEBSERVICE 分析器错误信息: 未能创建类型

    问题描述 分析器错误 说明: 在分析向此请求提供服务所需资源时出错.请检查下列特定分析错误详细信息并适当地修改源文件. 分析器错误信息: 未能创建类型"Service1". 源错误 ...