txt如何单独单独选择一列_散列| 单独链接以解决冲突

txt如何单独单独选择一列

Prerequisite: Hashing data structure

先决条件: 哈希数据结构

单独链接 (Separate chaining)

In separate chaining, we maintain a linked chain for every index in the hash table. So whenever there is a Collison the linked list is extended for that particular location of the hash table.

单独的链接中 ,我们为哈希表中的每个索引维护一个链接链。 因此,只要有Collison,链表都会扩展到哈希表的特定位置。

We can visualize the separate chaining method with the following example,

通过以下示例,我们可以可视化单独的链接方法:

Key set: {123, 456, 763, 656, 908, 238, 231}
Hash function: f(x) = x%10

Step 1: Inserting 123 in the hash map. So, location is 3.

步骤1:在哈希图中插入123。 因此,位置为3。

Index	keys
0	NULL
1	NULL
2	NULL
3	123->NULL
4	NULL
5	NULL
6	NULL
7	NULL
8	NULL
9	NULL

Step 2: Inserting 456 in the hash map. So, location is 3.

步骤2:在哈希图中插入456。 因此,位置为3。

Index	keys
0	NULL
1	NULL
2	NULL
3	123->NULL
4	NULL
5	NULL
6	456->NULL
7	NULL
8	NULL
9	NULL

Step 3: Inserting 763 in the hash map. So, location is 3.

步骤3:在哈希图中插入763。 因此,位置为3。

Index	keys
0	NULL
1	NULL
2	NULL
3	123->763->NULL
4	NULL
5	NULL
6	456->NULL
7	NULL
8	NULL
9	NULL

Step 4: Inserting 656 in the hash map. So, location is 6.

步骤4:在哈希图中插入656。 因此,位置为6。

Index	Keys
0	NULL
1	NULL
2	NULL
3	123->763->NULL
4	NULL
5	NULL
6	456->656->NULL
7	NULL
8	NULL
9	NULL

Step 5: Inserting 908 in the hash map. So, location is 8.

步骤5:在哈希图中插入908。 因此,位置为8。

Index	Keys
0	NULL
1	NULL
2	NULL
3	123->763->NULL
4	NULL
5	NULL
6	456->656->NULL
7	NULL
8	908->NULL
9	NULL

Step 6: Inserting 238 in the hash map. So, location is 8.

步骤6:在哈希图中插入238。 因此,位置为8。

Index	Keys
0	NULL
1	NULL
2	NULL
3	123->763->NULL
4	NULL
5	NULL
6	456->656->NULL
7	NULL
8	908->238->NULL
9	NULL

Step 7: Inserting 231 in the hash map. So, location is 8.

步骤7:在哈希图中插入231。 因此,位置为8。

Index	Keys
0	NULL
1	231->NULL
2	NULL
3	123->763->NULL
4	NULL
5	NULL
6	456->656->NULL
7	NULL
8	908->238->NULL
9	NULL

So, the above thing is called as separate chaining as we have chained the collided elements within the hash table.

因此,由于我们在哈希表中链接了冲突的元素,因此上述事情称为单独链接。

Performance analysis:

性能分析:

Load factor = n/m, 
n = number of keys inserted, 
m = number of indices in the hash table() size of hash table
Search complexity = O(load factor)
Insertion complexity = O(1)
Deletion complexity = O(load factor)

单独链接的优缺点 (Advantage and disadvantages of separate chaining)

Advantages are,

优点是

  • We can add as many keys as we want to add

    我们可以添加任意数量的键

  • It's simpler than open addressing to implement

    它比开放地址更容易实现

Disadvantages are,

缺点是

  • It uses extra spaces for links

    它为链接使用多余的空间

  • If the collision rate is high, the search complexity increases as load factor increases

    如果冲突率很高,则搜索复杂度会随着负载因子的增加而增加

单独链接的C ++实现 (C++ implementation of separate chaining)

//separate chaining
#include <bits/stdc++.h>
using namespace std;
class node {
public:
int data;
node* next;
node()
{
data = 0;
next = NULL;
}
node(int x)
{
data = x;
next = NULL;
}
};
node* add(node* head, int data)
{
if (head == NULL) {
head = new node(data);
return head;
}
node* temp = head;
while (temp->next) {
temp = temp->next;
}
temp->next = new node(data);
return head;
}
void print(node* head)
{
if (!head) {
cout << "NULL\n";
return;
}
node* temp = head;
while (temp) {
cout << temp->data << "->";
temp = temp->next;
}
cout << "NULL\n";
}
int main()
{
//set of input numbers
vector<int> arr{ 123, 456, 763, 656, 908, 238, 231 };
//initialize the hash table
//each entry of the hash table is a linkedlist
vector<node*> hash(10); //size of hashtable is 10
//using hash function f(x)=no of digits in x
for (int a : arr) {
hash[a % 10] = add(hash[a % 10], a);
}
cout << "Hash table is:\n";
for (int i = 0; i < 10; i++) {
cout << i << "---- ";
print(hash[i]);
}
return 0;
}

Output:

输出:

Hash table is:
0---- NULL
1---- 231->NULL
2---- NULL
3---- 123->763->NULL
4---- NULL
5---- NULL
6---- 456->656->NULL
7---- NULL
8---- 908->238->NULL
9---- NULL

翻译自: https://www.includehelp.com/data-structure-tutorial/hashing-separate-chaining-for-collision-resolution.aspx

txt如何单独单独选择一列

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

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

相关文章

[我研究]Behavior Based Software Theft Detection - Hawk

Xinran Wang, Yoon-Chan Jhi, Sencun Zhu, Peng LiuPSU 背景&#xff1a; Behavior Based Software Theft Detection的系统包含四个步骤&#xff1a; 1、Dynamic Analysis - 产生System Call, Call Stack, Dependences 2、Noise Filtering 3、Extract SCDG Birthmarks 4、Compa…

整除个数

描述 1、2、3… …n这n(0< n<1000000000)个数中有多少个数可以被正整数b整除。 输入 输入包含多组数据 每组数据占一行&#xff0c;每行给出两个正整数n、b。 输出 输出每组数据相应的结果。 样例输入 2 1 5 3 10 4 样例输出 2 1 2 思路&#xff1a;一开始…

2020计算机二级题库第14PPT,计算机二级考试MSOffice考精彩试题库ppt操作题附问题详解.doc...

文档介绍&#xff1a;请在【答题】菜单下选择【进入考生文件夹】命令,并按照题目要求完成下面的操作。注意:以下的文件必须保存在考生文件夹下文慧是新东方学校的人力资源培训讲师,负责对新入职的教师进行入职培训,其PowerPoint演示文稿的制作水平广受好评。最近,她应北京节水展…

操作系统 系统开销比率_操作系统中的最高响应比率下一个(HRRN)调度

操作系统 系统开销比率操作系统中的HRRN调度是什么&#xff1f; (What is HRRN Scheduling in Operating System?) HRRN is the abbreviation of Highest Response Ratio Next Scheduling. It is an optimal scheduling algorithm. HRRN是最高响应率下一个调度的缩写 。 这是…

利用堆栈做循环

程序&#xff1a; #include "stdio.h" int main(int argc,char *argv[]) {char *str"%d";printf("hello world");__asm{ log:lea eax,logpush eaxlea ebx,strpush ebxpush eaxcall printfret 8}return 0;}运行&#xff1a;一直死循环运行下去 …

c# 多线程异步demo

一个 c# winform 多线程异步demo&#xff0c;分享下。 因为例子都很简单&#xff0c;所以不多说明&#xff0c;自己下载吧。转载于:https://www.cnblogs.com/chaobao/archive/2011/08/18/CSharpSync.html

(转)项目管理知识体系术语 123

项目管理知识体系术语(一)本词汇集包括和不包括的术语这个词汇集包括的词汇是&#xff1a;对于项目管理是唯一的&#xff0c;或接近于唯一的词汇(例如&#xff1a;范围说明&#xff0c;工作单元&#xff0c;工作分解结构&#xff0c;关键线路法)。对于项目管理是不是唯一的&…

矩形的个数

描述 在一个3*2的矩形中&#xff0c;可以找到6个1*1的矩形&#xff0c;4个2*1的矩形3个1*2的矩形&#xff0c;2个2*2的矩形&#xff0c;2个3*1的矩形和1个3*2的矩形&#xff0c;总共18个矩形。 给出A&#xff0c;B,计算可以从中找到多少个矩形。 输入 本题有多组输入数据&a…

计算机编程要哪方面天赋,编程要哪门子天赋

开局一张图写代码真的需要天赋吗&#xff1f;有句话是这样说的&#xff1a;论大家的努力程度&#xff0c;远不到拼天赋的时候。我认为所谓的天赋&#xff0c;应该是行业内Top10%水平才需要天赋&#xff0c;比如Linux缔造者Linus Torvalds&#xff0c;苹果发明者斯蒂夫沃兹尼亚克…

VBA之EXCEL删除和设置单元格行高等

‘删除Sheet1上的单元格区域A1:D10,并将其余单元格左移以填补被删除单元格的位置 Sheet1.Range(“A1:D10”).Delete Shift:xlShiftToLeft ‘删除指定行 Range(“1:1”).Delete ‘删除指定列 Columns(5).Delete ‘删除当前行 ActiveCell.EntireRow.Delete ‘删除工作表中的重复行…

java void方法_Java对象类的最终void wait(long ms)方法,包含示例

java void方法对象类最终无效等待(长毫秒) (Object Class final void wait(long ms)) This method is available in java.lang.Object.wait(long ms). 此方法在java.lang.Object.wait(long ms)中可用。 This method causes the current thread to wait for a specified amount …

C和汇编----字符串

字符串是以空字符&#xff08;\0&#xff09;结尾的char类型数组。 0x01 定义字符串和初始化 用双引号括起来的内容称为字符串字面量&#xff0c;也叫字符串常量&#xff0c;双引号中的字符串和编译器自动加入\0字符&#xff0c;都作为字符串存储在内存中 #include "st…

出现此版本的sql server不支持用户实例登陆标志 问题的解决方法

场景: 开发工具vs2005 数据库 sql 2005加入了Enterprise Libraty后,新增了一个data access application block,在写ConnectString的时候,出现这个错误提示,解决办法:在连接属性的设置里边,点高级,将User Instance 设置为false,默认的true,所以才导致这个问题的出现.设置好后,重…

计算机编程输入与输出,计算机编程语言的发展与输入输出设备的使用

计算机编程语言的发展与输入输出设备的使用辽宁大学学报自然科学版第32卷 第2期 2005年JOURNALOFLIAONINGUNIVERSITYNaturalSciencesEditionVol.32 No.2 2005计算机编程语言的发展与输入输出设备的使用宋明杰3(辽宁大学信息科学与技术学院,辽宁沈阳110036)摘 要:在编程中涉…

大小写互换

描述 现在给出了一个只包含大小写字母的字符串&#xff0c;不含空格和换行&#xff0c;要求把其中的大写换成小写&#xff0c;小写换成大写&#xff0c;然后输出互换后的字符串。 输入 第一行只有一个整数m&#xff08;m<10),表示测试数据组数。 接下来的m行&#xff0c…

远控免杀专题1---基础篇

0x01 免杀概念 免杀&#xff0c;也就是反病毒与反间谍的对立面&#xff0c;英文为Anti-AntiVirus&#xff08;简写 Virus AV&#xff09;&#xff0c;逐字翻译就是反-反病毒&#xff0c;翻译为反病毒技术。 0x02 杀毒软件检测方法 1、扫描结束 扫描压缩包技术&#xff1a;即…

查询所有存储过程

--查询所有存储过程selectPr_Name as[存储过程], [参数]stuff((select&#xff0c;[Parameter]from( selectPr.Name asPr_Name,parameter.name Type.Name (convert(varchar(32),parameter.max_length))asParameter fromsys.procedures Pr leftjoinsys.parameters…

使用JavaScript中的示例编号MAX_VALUE属性

数字MAX_VALUE属性 (Number MAX_VALUE Property) MAX_VALUE Property is a Number property in JavaScript and it is used to get the maximum value of a number that is possible in JavaScript. MAX_VALUE属性是JavaScript中的Number属性&#xff0c;用于获取JavaScript中可…

文件复制器

文件复制器 2007.08.18.0地狱门神(F.R.C.)http://files.cnblogs.com/Rex/FileCopier.rar 本软件用于复制或更新一个文件夹中的文件到另一个文件夹中。 当你需要经常通过向移动硬盘复制文件来备份重要数据时&#xff0c;可能会遇到如下情况&#xff1a;(1)电脑USB接口过旧&#…

远控免杀专题2---msfvenom的隐藏参数

0x01 msfvenom简介 msfvenom是msfpayload和msfencode的结合体&#xff0c;与2015年6月8日取代了msfpayload和msfencode。在此之后&#xff0c;metasploit-framwork下面的msfpayload&#xff08;载荷生成器&#xff09;&#xff0c;msfencoder&#xff08;编码器&#xff09;&a…