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. logstash导入DNS解析数据到es中,中间有filebeat

    这个过程中,主要用logstash处理数据的时候不好处理. 在logstash-sample.conf这个配置文件中的配置,我用这个监控filebeat的5044端口 # Sample Logstas ...

  2. 20201204-3 opp编程好处

    面向对象编程(Object-Oriented Programming )介绍 对于编程语言的初学者来讲, OOP不是一个很容易理解的编程方式,大家虽然都按老师讲的都知道0OP的三大特性是 继承.封装. ...

  3. 三方登录微博url接口

    1.创建apps/oauth模块进行oauth认证 '''2.1 在apps文件夹下新建应用: oauth''' cd syl/apps python ../manage.py startapp oa ...

  4. 记一次HBase的NotServingRegionException问题

    1. 问题 在hbase测试集群上,访问一些hbase表,均报类似下面的错误:region不可用 Wed Oct 28 14:00:56 CST 2020, RpcRetryingCaller{glo ...

  5. Flink相对于Spark的优点

    Flink相对于Spark的优点 容错 Flink 基于两阶段提交实现了精确的一次处理语义. Spark Streaming 只能做到不丢数据,但是有重复. 反压 Flink 在数据传输过程中使用了分 ...

  6. JYadmin-react-antd react+antd封装的优秀后台模板集成方案("^1.0.0")

    版本:[ "JYadmin-react-antd": "^1.0.0"] 版权所有:微信公众号[微新悦] 原文链接:https://www.weixinyue. ...

  7. 第一天——编程语言与python

    ------------恢复内容开始------------ what's the python? python是一门编程语言,编程语言就是人用来和计算机沟通的语言,语言就是人与人,人与事物进行沟通的 ...

  8. idea run dashbord使用

    idea 中使用dashbord可以迅速开启多个服务方便进行本地测试 开启步骤 1. 打开idea菜单 view-> toolWindows ->service 选项 2. 打开底部的se ...

  9. 手把手教你用SonarQube+Jenkins搭建--前端项目--代码质量管理平台 (Window系统)

    前言 网上教程大多介绍的是Linux系统下SonarQube+Jenkins如何使用,这是因为这两款软件一般都是部署在服务器上,而大多数服务器,采用的都是Linux系统.大多数服务器用Linux的原因 ...

  10. 栈面板类StackPane?

    创建栈面板,将在其上放置两个按钮,并用样式属性设置按钮和栈面板的外观样式. package yuan; //栈面板的应用 import javafx.application.Application; ...