散列碰撞_散列中的碰撞和碰撞解决技术

散列碰撞

Prerequisite: Hashing data structure

先决条件: 哈希数据结构

碰撞 (Collisions)

Hash functions are there to map different keys to unique locations (index in the hash table), and any hash function which is able to do so is known as the perfect hash function. Since the size of the hash table is very less comparatively to the range of keys, the perfect hash function is practically impossible. What happens is, more than one keys map to the same location and this is known as a collision. A good hash function should have less number of collisions.

哈希函数可以将不同的键映射到唯一的位置(哈希表中的索引),任何能够做到这一点的哈希函数都称为完美哈希函数。 由于哈希表的大小相对于键范围而言非常小,因此理想的哈希函数实际上是不可能的。 发生的事情是,有多个键映射到同一位置,这称为碰撞 。 良好的哈希函数应具有较少的冲突数。

To understand what collision is let's check the below example,

要了解什么是碰撞,让我们检查以下示例,

Say, the set of keys are;
{123, 124, 135, 1267, 2378, 9087} 
and hash table size is 10(0-9 indices)
Now,
If our hashing function is
F(x)=digits in x
Then
123->3
124->3
135->3
1267->4
2378->4
9087->4

The hash table will look like,

哈希表看起来像

collisions in hashing

In the above example, we can see though there are 10 indices only 2 are being used and the collision rate is too high. 123, 124, 135 have collided while 1267, 2378, 9087 have collided.

在上面的示例中,我们可以看到尽管有10个索引,但仅使用了2个,并且冲突率太高。 123、124、135发生了碰撞,而1267、2378、9087发生了碰撞。

#include <bits/stdc++.h>
using namespace std;
//collision
int main()
{
//set of input numbers
vector<int> arr{ 123, 124, 135, 1267, 2378, 9087 };
//using hashh function f(x)=no of digits in x
cout << "using hashh function 1\n";
for (int a : arr) {
cout << a << "->" << to_string(a).length() << endl;
}
return 0;
}

Output:

输出:

using hashh function 1
123->3
124->3
135->3
1267->4
2378->4
9087->4

碰撞解决技术 (Collision Resolution Techniques)

Collision resolution is finding another location to avoid the collision. The most popular resolution techniques are,

碰撞解决方案正在寻找另一个位置来避免碰撞。 最受欢迎的解析技术是

  1. Separate chaining

    单独链接

  2. Open addressing

    开放式寻址

Open addressing can be further divided into,

开放式寻址可以进一步分为:

  1. Linear Probing

    线性探测

  2. Quadratic Probing

    二次探测

  3. Double hashing

    双重哈希

翻译自: https://www.includehelp.com/data-structure-tutorial/collisions-in-hashing-and-collision-resolution-techniques.aspx

散列碰撞

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380513.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

call和ret(f)指令

call指令 CPU执行call指令时&#xff0c;进行两步操作 将当前的ip&#xff08;eip&#xff09;或者cs和ip&#xff08;ecs和eip&#xff09;压入栈中跳转到标号处 call 标号 将当前的IP压栈后&#xff0c;转到标号处执行指令 相当于&#xff1a; push ip jmp near ptr 标号…

天翼云linux远程密码不对,天翼云主机远程连接

天翼云主机如何进行远程连接&#xff1f;操作系统不同自然连接方式也是不一样&#xff0c;今天我们分别介绍一下天翼云Windows主机远程连接和Linux云主机远程连接的方法。一、Windows云主机远程连接(1)在电脑连接网络的情况下&#xff0c;点击桌面左下角的windows图标&#xff…

pku2503 Babelfish

额&#xff0c;跟hdu的1075很像&#xff0c;不过比那题简单多了&#xff0c;就是读入时有点麻烦&#xff0c;用到了一个函数 具体看代码吧&#xff0c;这题没什么&#xff0c;不过我的内存开了太多了&#xff0c;不解…… #include<stdio.h> #include<string.h> #i…

JAVA JDK环境渲染

①&#xff08;随便在哪个盘里都行&#xff09;创建一个文件夹名称&#xff1a;Java&#xff1b; ②在文件夹Java下创建一个子文件夹 名称&#xff1a;jdk&#xff1b; ③在子文件夹jdk下再创建一个子文件夹 名称jre&#xff1b; &#xff08;文件夹名称随便&#xff0c;我这…

英语单词 搞笑着背

背单词的过程是枯燥的&#xff0c;一天紧张的学习用下面的方法检查一下今天记住了多少&#xff1a;&#xff09; 根据中英文的谐音&#xff0c;不知对大家背单词是否有用&#xff01;  peevish------"劈为尸体"------暴躁的  hermit-------"何处觅她"---…

linux查看网卡硬件 lsw,linux系统配置管理小测试试卷答案

广东岭南职业技术学院Linux操作系统试题卷一、选择题&#xff1a;(每题2分&#xff0c;共64分)1&#xff0e;Linux操作系统内核创始人是( C )。A. Bill GatesB. Richard StallmanC. Linus TorvaldsD. Dennis MRitchie、Ken Thompson2、下面哪个Linux命令可以一次显示一页内容&a…

turbo c填充图形_C / C ++中的图形:Turbo C编译器中的简介和图形模式

turbo c填充图形In this advanced learning tutorial, you will learn more about the C/C feature "Graphics" by using which you can make your C program even more interactive and attractive. Graphics in C/C can be used to draw different shapes, animati…

使用C和汇编实现一个加法操作

在C/C嵌入汇编指令格式&#xff1a; __asm{;汇编指令 }代码&#xff1a; #include "stdio.h"int main() {int a1;int b2;int c0;__asm{mov eax,amov ebx,badd eax,ebxmov c,eax}printf("ab%d\n",c);return 0; }结果&#xff1a;

神话人物的现代版简历

她丈夫在河北当建筑工人&#xff0c;工程塌方&#xff0c;被砸死在下面。她要求赔偿&#xff0c;包工头不肯。她起诉到法院&#xff0c;败诉。她上诉&#xff0c;再次败诉。她只好上访&#xff0c;从山东一次次来到河北&#xff0c;当局抓她&#xff0c;关她&#xff0c;在精神…

restrict(TextField.restrict 属性)

restrict&#xff08;TextField.restrict 属性&#xff09; public restrict : String 指示用户可输入到文本字段中的字符集。如果 restrict 属性的值为 null&#xff0c;则可以输入任何字符。如果 restrict 属性的值为空字符串&#xff0c;则不能输入任何字符。如果 restrict …

字符串 charat_Java | String.charAt(index)| 从字符串中按索引获取字符

字符串 charatString.charAt() function is a library function of String class, it is used to get/retrieve the specific character from a string. Where, the index starts from 0 and ends to String.lenght-1. String.charAt()函数是String类的库函数&#xff0c;用于…

移动硬盘linux逻辑分区的区别,主磁盘分区、扩展磁盘分区、逻辑分区的区别

硬盘分区有三种&#xff0c;主磁盘分区、扩展磁盘分区、逻辑分区。一个硬盘可以有一个主分区&#xff0c;一个扩展分区&#xff0c;也可以只有一个主分区没有扩展分区。逻辑分区可以若干。主分区是硬盘的启动分区&#xff0c;他是独立的&#xff0c;也是硬盘的第一个分区&#…

hdu1247

一道水题&#xff0c;居然改错改了一个多小时 题目的意思是其实就是找出一个单词&#xff0c;前半部是一个出现过的单词&#xff0c;后半部也是&#xff0c;记住&#xff0c;要严格满足这个条件 所以&#xff0c;其实也就是先查找一个单词的是否有前缀&#xff0c;再用这个单词…

FPU数据寄存器

FPU有8个独立的、可寻址的80位数据寄存器R0-R7&#xff0c;如下图所示&#xff0c;这些寄存器合称为寄存器栈。FPU 状态字中名为 TOP 的一个 3 位字段给出了当前处于栈顶的寄存器编号。例如&#xff0c;在下图中&#xff0c;TOP 等于二进制数 011&#xff0c;这表示现在栈顶为 …

计算当月的天数(sql)

declare dt datetime set dtgetdate() --set dt2006-8-8 SELECT 32-Day(dt32-Day(dt)) 转载于:https://www.cnblogs.com/super-yc/archive/2006/11/04/549646.html

使用Java中的equals()和compareTo()方法比较字符串

Given strings and we have to compare them using equals() and compareTo() method. 给定字符串&#xff0c;我们必须使用equals()和compareTo()方法进行比较。 Java string equals() method Java字符串equals()方法 Java string equals() method compares the content of …

poj 2528_2

代码&#xff1a; #include<iostream> #include<fstream>using namespace std;struct e{int l,r;bool isa; };e tree[80001]; int n;struct f{int num,s,l; };f b[20001];int c[10001][2];int cmp(const void *a,const void *b){f *s(f*)a;f *t(f*)b;return s->…

linux 命令修改网络,linux网络命令学习

用命令修改的均为临时生效&#xff0c;重启后失效&#xff0c;要想永久生效需更改配置文件设置主机名vi etc/sysconfig/network查看主机名hostname设置IP地址ifconfig 网卡名 IP地址 netmask 子网掩码ifconfig etho 10.0.0.1 netmask 255.0.0.0查看某快网卡的状况ifconfig 网卡…

素数求和问题

描述 现在给你N个数(0< N<1000) ,现在要求你写出一个程序&#xff0c;找出这N个数中的所有素数&#xff0c;并求和。 输入 第一行给出整数M(0< M<10)代表多少组测试数据 每组测试数据第一行给你N&#xff0c;代表该组测试数据的数量。 接下来的N个数为要测试的…