网站大量收购独家精品文档,联系QQ:2885784924

数据结构第八章hash新版课件.ppt

  1. 1、本文档共53页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构第八章hash新版课件

散列(Hashing)存贮 p353;这种存贮线性表F的方法,称为散列存贮。称函数h(x)为散列函数(HASH函数)。 称存放结点的数组T(m)为散列表(Hash表). 设F是含有六个结点的线性表,其中K0=(9,e) ,k1=(12,b), k2=(20,e), K3=(26,a), k4=(34,d), k5=(48,f). 若取散列函数h(x)=x mod 10,并使用能存放十个结点的数组T[10]作为Hash表,则下图表示了F的散列存贮的状况。;0 1 2 3 4 5 6 7 8 9;;静态散列方法; ; 采用的散列函数是 hash(x) = x % 73 + 13420 其中,“%”是除法取余操作。 则有:hash(12361) = hash(07250) = hash(03309) = hash(30976) = 13444。就是说, 对不同的关键码, 通过散列函数的计算, 得到了同一散列地址。我们称这些产生冲突的散列地址相同的不同关键码为同义词。 由于关键码集合比地址集合大得多, 冲突很难避免。所以对于散列方法, 需要讨论以下两个问题: ;构造散列函数时的几点要求: 散列函数应是简单的,能在较短的时间内计 算出结果。 散列函数的定义域必须包括需要存储的全部 关键码, 如果散列表允许有 m 个地址时, 其 值域必须在 0 到 m-1 之间。 ;一、开式寻址法解决冲突;1.建立Hash表的插入运算。 为了把键值k存入Hash表,先计算出h(k)=i. 如果t[i] 是一个空位置(即t[i]=0),那么把k存入t[i],插入过程结束; 如果t[i]不是空位置(即t[i]≠0),那么再判断t[i]是否等于k, 若t[i]=k,则键值k已在Hash表中,插入过程结束; 否则,t[i]已被另一个键值所占用(发生冲突),此时必须为k找另一个空位置,最简单的办法是进行线性探测,我们可使用下面的循环探测地址序列:;; ;;;;;; ; ; ;; ;;Collision resolution by chaining We can take the hash table itself as an array of pointers to the record,that is,as an array of linked lists. It is traditional to refer to the linked lists from hash as chains and call this method collision resolution by chaining. 把来自hash表中的一些链表叫做链,称该方法为拉链法。;1.Advantage of chaining The first,is that considerable space may be saved. Since the hash table is a continuous array, enough space must be set aside at compilation time to avoid overflow. If the hash table contains only pointers to the records,pointers that require only one word each,the size of the hash table may be reduced by a large factor and will become small relative to the space available for the record,or for other uses. ;The second advantage of keeping only pointers in the hash table is that it allows simple and efficient collision handing. We need only add a link field to each record, and organize all the records with a single hash address as linked list. Finally, deletion becomes a quick and easy task in chained hush table. 2. Disadvantage of chaining All the links require space. ;二、用拉链法解决冲突

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档