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. 【NOI2018】你的名字(SAM & 线段树合并)

    Description Hint Solution 不妨先讨论一下无区间限制的做法. 首先"子串"可以理解为"前缀的后缀",因此我们定义一个 \(\lim(i) ...

  2. rsync 参数说明及使用参数笔记好文摘抄

    一.前言 最近发现rsync挺好用的--不过参数有点多,所以这儿写一篇给自己以后要用的时候做个参考. 二.参数说明 这儿全是我翻资料连蒙带猜(有些实在是不好解释)翻译出来的,请各位转载的留个名啊,虽然 ...

  3. 下载hotspot源码

    http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/tags 比如jdk8u262-ga ,最右边可以找到它的id,就是1c6e1f187fdc,下载地址: ...

  4. ubuntu 18 安装xgboost GPU版本

    综合上述两个帖子: https://www.cnblogs.com/huadongw/p/6161145.html https://blog.csdn.net/u011587516/article/d ...

  5. 阿里云,批量删除oss所有的bucket

    需求:多个账号需要清空bucket.阿里不支持一键删除,很是麻烦. 使用的工具是osscmd,先下载osscmd后解压,然后在同级目录创建两个文件,一个写AccessKeySecret,另一个写Acc ...

  6. 快用Django REST framework写写API吧

    Django默认是前后端绑定的,提供了Template和Form,现在流行前后端分离项目,Python大佬坐不住了,于是便有了Django REST framework:https://github. ...

  7. Unity 3D里相机的平滑跟随(转)

    1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 public class ...

  8. springMVC基础讲解

    一.初识三层架构: 在讲解springMVC之前,先来了解一下什么是三层架构.我们的开发架构一般都是基于两种形式,一种是C/S架构(客户端/服务器),另一种是B/S架构(浏览器服务器).在javaEE ...

  9. centos 7 yum 安装 python3

    sudo yum install epel-release sudo yum install python34参考:http://stackoverflow.com/questions/8087184 ...

  10. Jupyter Notebook在多个虚拟环境配置与使用

    1 问题描述 使用Anaconda配置了包括Pytorch.Tensorflow等多个虚拟环境后,依然无法使用Jupyter Notebook选择不同的虚拟环境运行代码,问题如下图所示. 2 解决方法 ...