ImageVerifierCode 换一换
格式:PPT , 页数:20 ,大小:145KB ,
资源ID:7281975      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7281975.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(算法设计与分析10HashTable.ppt)为本站会员(lxhqcj)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

算法设计与分析10HashTable.ppt

1、Hashing,Algorithm : Design & Analysis 10,In the last class,Implementing Dictionary ADT Definition of red-black tree Black height Insertion into a red-black tree Deletion from a red-black tree,Hashing,Hashing Collision Handling for Hashing Closed Address Hashing Open Address Hashing Hash Functions Ar

2、ray Doubling and Amortized Analysis,Hashing: the Idea,Key Space,Hash Function,E0,E1,Eh-1,Value of a specific key,A calculated array index for the key,Very large, but only a small part is used in an application,In feasible size,Index distributionCollision handling,Ek,x,H(x)=k,Collision Handling: Clos

3、ed Address,Each address is a linked list,Closed Address: Analysis,Assumption: simple uniform hashing: for j=0,1,2,.,h-1, the average length of the list at Ej is n/h. The average cost of an unsuccessful search: Any key that is not in the table is equally likely to hash to any of the h address. The av

4、erage cost to determine that the key is not in the list Eh(k) is the cost to search to the end of the list. So, the cost of an unsuccessful search is n/h.,Closed Address: Analysis(cont.),The average cost of a successful search: Define =n/h as load factor,Number of elements in front of the searched o

5、ne in the same linked list.,Cost for computing hashing,Collision Handling: Open Address,All elements are stored in the hash table, no linked list is used. So, , the load factor, can not be larger than 1. Collision is settled by “rehashing”: a function is used to get a new hashing address for each co

6、llided address, i.e. the hash table slots are probed successively, until a valid location is found. The probe sequence can be seen as a permutation of (0,1,2,., h-1),Commonly Used Probing,Linear probing:Given an ordinary hash function h, which is called an auxiliary hash function, the hash function

7、is: h(k,i) = (h(k)+i) mod m (i=0,1,.,m-1) Quadratic Probing:Given auxiliary function h and nonzero auxiliary constant c1 and c2, the hash function is: h(k,i) = (h(k)+c1i+ c2i2) mod m (i=0,1,.,m-1) Double hashing:Given auxiliary functions h1 and h2, the hash function is: h(k,i) = (h1(k)+ ih2(k) mod m

8、 (i=0,1,.,m-1),Linear Probing: an Example,H,Index,0,1,2,3,4,5,6,7,Hash function: h(x)=5x mod 8,1055,1492,1776,1918,1812,1945,Rehash function: rh(j)=(j+1) mod 8,hashing,rehashing,1812,chain of rehashings,1945,hashing,Equally Likely Permutations,Assumption: each key is equally likely to have any of th

9、e m! permutations of (1,2.,m-1) as its probe sequence. Note: both linear and quadratic probing have only m distinct probe sequence, as determined by the first probe.,Analysis for Open Address Hash,Assuming uniform hashing, the average number of probes in an unsuccessful search is at most 1/(1-) (=n/

10、m1),Analysis for Open Address Hash,Assuming uniform hashing, the average cost of probes in an successful search is at most (=n/m1),For your reference: Half full: 1.387; 90% full: 2.559,Hashing Function,A good hash function satisfies the assumption of simple uniform hashing. Heuristic hashing functio

11、ns The divesion method: h(k)=k mod m The multiplication method: h(k)=m(kA mod 1) (0A1) No single function can avoid the worst case (n), so, “Universal hashing” is proposed.Rich resource about hashing function:Gonnet and Baeza-Yates: Handbook of Algorithms and Data Structures, Addison-Wesley, 1991,Ar

12、ray Doubling,Cost for search in a hash table is (1+), then if we can keep constant, the cost will be (1) Space allocation techniques such as array doubling may be needed. The problem of “unusually expensive” individual operation.,Looking at the Memory Allocation,hashingInsert(HASHTABLE H, ITEM x)int

13、eger size=0, num=0;if size=0 then allocate a block of size 1; size=1;if num=size thenallocate a block of size 2size;move all item into new table;size=2size;insert x into the table;num=num+1; return,Elementary insertion: cost 1,Insertion with expansion: cost size,Worst-case Analysis of the Insertion,

14、For n execution of insertion operations A bad analysis: the worst case for one insertion is the case when expansion is required, up to n So, the worst case cost is in O(n2). Not the expansion is required during the ith operation only if i=2k, and the cost of the ith operation,Of course NOT !,Amortiz

15、ed Time Analysis,Amortized equation: amortized cost = actual cost + accounting cost Design goals for accounting cost In any legal sequence of operations, the sum of the accounting costs is nonnegative. The amortized cost of each operation is fairly regular, in spite of the wide fluctuate possible fo

16、r the actual cost of individual operations.,Accounting Scheme for Stack Push,Push operation with array doubling No resize triggered: 1 Resize(n2n) triggered: tn+1 (t is a constant) Accounting scheme (specifying accounting cost) No resize triggered: 2t Resize(n2n) triggered: -nt+2t So, the amortized cost of each individual push operation is 1+2t(1),Home Assignment,pp.302- 6.1 6.2 6.18 6.19,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报