下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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網(wǎng)a案d答9419996791989后h課(b)k0123456789.www4199-25-(c)m0123456789oc.w4199網(wǎng)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網(wǎng)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.網(wǎng)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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 貴陽職業(yè)技術(shù)學(xué)院《房地產(chǎn)項(xiàng)目投資與融資》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025年天津建筑安全員-C證考試(專職安全員)題庫附答案
- 2025河南省安全員-C證考試(專職安全員)題庫附答案
- 貴陽康養(yǎng)職業(yè)大學(xué)《社會(huì)危機(jī)管理》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣州中醫(yī)藥大學(xué)《普通化學(xué)及實(shí)驗(yàn)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025山西建筑安全員考試題庫
- 廣州醫(yī)科大學(xué)《體育產(chǎn)業(yè)學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣州現(xiàn)代信息工程職業(yè)技術(shù)學(xué)院《汽車拖拉機(jī)構(gòu)造學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025云南省安全員-C證考試題庫
- 2025江西省安全員A證考試題庫
- TSEESA 010-2022 零碳園區(qū)創(chuàng)建與評(píng)價(jià)技術(shù)規(guī)范
- GB/T 3683-2011橡膠軟管及軟管組合件油基或水基流體適用的鋼絲編織增強(qiáng)液壓型規(guī)范
- GB/T 3003-2017耐火纖維及制品
- GB/T 18920-2020城市污水再生利用城市雜用水水質(zhì)
- GB/T 13203-2021摩托車輪胎性能試驗(yàn)方法
- GB 17267-1998液化石油氣瓶充裝站安全技術(shù)條件
- 上期開特下期必開特規(guī)律
- GA/T 744-2013汽車車窗玻璃遮陽膜
- 客戶投訴處理流程
- 空氣調(diào)節(jié)試卷答案
- 《教師口語教程》
評(píng)論
0/150
提交評(píng)論