下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 Chapter5: Hashingm5.1 (a) On the assumption that we add collisions to the end of the list (which is the easierway ifoa hash table is being built by hand), the separate chaining hash table that results is shownhere.c01234567.8w网a案d答9419996791989后h课(b)k0123456789.www4199-25-(c)m0123456789oc.w4199网a(d
2、) 1989 cannot be inserted into the table because hash (1989) = 6, and the alternative locations案25, 1, 7, and3 arealreadytaken. Thetableat this point is as follows:d答0后h14371课23456789k.43444199ww5.2 When rehashing, we choose a table size that is roughly twice as large and prime. In ourwcase,the appr
3、opriatenewtablesizeis 19, with hash function h(x) = x(mod 19).(a) Scanning down the separate chaining hash table, the new locations are 4371 in list 1,1323 in list 12, 6173 in list 17, 4344 in list 12, 4199 in list 0, 9679 in list 8, and 1989 in list13.(b) The new locations are 9679 in bucket 8, 437
4、1 in bucket 1, 1989 in bucket 13, 1323 inbucket 12, 6173 in bucket 17, 4344 in bucket 14 because both 12 and 13 are already occu-pied, and4199 in bucket0.-26-(c) The new locations are 9679 in bucket 8, 4371 in bucket 1, 1989 in bucket 13, 1323 inbucket 12, 6173 in bucket 17, 4344 in bucket 16 becaus
5、e both 12 and 13 are already occu-pied, and4199 in bucket0.m(d) The new locations are 9679 in bucket 8, 4371 in bucket 1, 1989 in bucket 13, 1323 inbucket 12, 6173 in bucket 17, 4344 in bucket 15 because 12 is already occupied, and 4199in bucket0.o5.4 We must be carefulnot to rehash too often. Let p
6、 be the threshold (fractionof table size)atwhich we rehash to a smaller table. Then if the new table has size N, it contains 2pN ele-ments. This table will require rehashing after either 2N 2pNBalancing these costs suggests that a good choice is p = 2/ 3. For instance, suppose wehave a table of size
7、 300. If we rehash at 200 elements, then the new table size is N = 150,insertions or pN deletions.candwecando either100 insertions or 100 deletions u.ntil anewrehashis required.If we know that insertions are more frequent than deletions, then we might choose p to besomewhat larger. If p is too close
8、 to 1.0, however, then a sequence of a small number ofdeletions followed by insertions can cause frequent rehashing. In the worst case, if p = 1.0,then alternatingdeletions andinsertions both requirerehashing.a5.5 (a) Since each table slot is eventually probed, if the table is not empty, the collisi
9、on can be网ww-27-O(M +N) space.Another method of implementing these operations is to use a search tree instead of a hashtable; a balanced tree is required because elements are inserted in the tree with too muchmorder. A splay tree might be particularly well suited for this type of a problem because i
10、tdoes well with sequential accesses. Comparing the differentways of solving the problem isagood programmingassignment.o5.8 The table size would be roughly 60,000 entries. Each entry holds 8 bytes, for a total of480,000 bytes.c(d) As discussed in part (b), the algorithm will fail to detect one in ten
11、 misspellings on aver-5.9 (a)This statement is true.(b) If a word hashes to a location with value 1, there is no guarantee that the word is in thedictionary. It is possible that it just hashes to the same value as some other word in the dic-.tionary. In our case, the table is approximately 10% full
12、(30,000 words in a table of(e) A 20document would have about 60 misspellings. This algorithm would beexpected to detect 54. A table three times as large would still t in about 100K bytes ander of errors to two. This is good enough for many applications,300,007), so there is a 10% chance that a word
13、that is not in the dictionary happens to hashout to alocation with value1.w(c)300,007 bits is 37,501 bytes on most machines.网age.a案reduce the expected numbd答especially since spelling detection is a very inexact science. Many misspelled words (espe-cially short ones) are still words. For instance, ty
14、ping them instead of then is a misspelling后that wont bedetehctedby anyalgorithm.5.10 To each hash tab课le slot, we can add an extra eld that well call WhereOnStack, and we cankeepan extrastack. Whenaninsertion is rst performedinto aslot, wepush the address(ornumber)of the slot onto the stack and set the WhereOnStack eld to point to the top of thestack. When we accessa hash table slot, we checkthat WhereOnStack points to avalid partof the stack and that t
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度合伙人撤资合同:股权变现与公司运营保障协议
- 2025合同模板总公司与分公司合作协议范本
- 二零二五年度涂料工程环保风险评估合同
- 2025合法的授权代理合同范本
- 2025外商投资企业土地使用合同样本
- 涂料销售合同
- 2025年度水利工程监理投标代理服务合同
- 二零二五年度水泥地砖品牌授权与加盟连锁合同
- 2025电子产品购销合同可复制
- 2025年专利实施许可合同协议(2篇)
- 2025年上半年长沙市公安局招考警务辅助人员(500名)易考易错模拟试题(共500题)试卷后附参考答案
- 2025河北邯郸世纪建设投资集团招聘专业技术人才30人高频重点提升(共500题)附带答案详解
- 慈溪高一期末数学试卷
- 贵州省黔东南州2024年七年级上学期数学期末考试试卷【附答案】
- 企业招聘技巧培训
- 重大事故隐患判定标准与相关事故案例培训课件
- 2024年度节后复工建筑施工安全培训交底
- 2024年内蒙古电力集团招聘笔试参考题库含答案解析
- 保洁服务品质履约评估报告
- 火龙罐综合灸疗法
- 红色中国风西安旅游PPT模板
评论
0/150
提交评论