Then it is enough if the bucket address table has

Info iconThis preview shows pages 5–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Then it is enough if the bucket address table has just four entries instead of eight. For the purpose of this answer, we do not do the coalescing. b. Delete 31: From the answer to 11.6, change the last bucket to:
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Chapter 11 Indexing and Hashing 2 23 7 c. Insert 1: From the answer to 11.6, change the frst bucket to: 2 17 1 d. Insert 15: From the answer to 11.6, change the last bucket to: 2 15 23 7 11.8 Answer: The pseudocode is shown in Figure 11.1. 11.9 Answer: Let i denote the number o± bits o± the hash value used in the hash table. Let bsize denote the maximum capacity o± each bucket. The pseudocode is shown in Figure 11.2. Note that we can only merge two buckets at a time. The common hash prefxo±the resultantbucketwillhave length one lessthan the two buckets merged. Hence we look at the buddy bucket o± bucket j di±±ering ±rom it only at the last bit. I± the common hash prefx o± this bucket is not i j , then this implies that the buddy bucket has been ±urther split and merge is not possible. When merge is success±ul, ±urther merging may be possible, which is handled by a recursive call to coalesce at the end o± the ±unction. 11.10 Answer: I± the hash table is currently using i bits o± the hash value, then maintain a count o± buckets ±or which the length o± common hash prefx is exactly i . Consider a bucket j with length o± common hash prefx i j . I± the bucket is being split, and i j is equal to i , then reset the count to 1. I± the bucket is being split and i j is one less that i , then increase the count by 1. It the bucket i± being coalesced, and i j is equal to i then decrease the count by 1. I± the count becomes 0, then the bucket address table can be reduced in size at that point. However, note that i± the bucket address table is not reduced at that point, then the count has no signifcance a±terwards. I± we want to postpone the reduction, we have to keep an array o± counts, i.e. a count ±or each value o±
Background image of page 6
Exercises 7 function fndIterator(value V ) { /* Returns an iterator For the search on the value V */ Iterator iter (); Set iter .v alue = V ; Set C = root node while ( C is not a leaF node) begin Let i = samllest number such that V <= C . K i iF there is no such number i then begin Let P m = last non-null pointer in the node Set C = C . P m ; end else Set C = C . P i ; end /* C is a leaF node */ Let i be the least value such that K i = V if there is such a value i then begin Set iter . index = i ; Set iter . page = C ; Set iter . acti v e = T RUE ; end else if ( V is the greater than the largest value in the leaF) then begin if ( C . P n . K 1 = V ) then begin Set iter . page = C . P n ; Set iter . index = 1; Set iter . acti v e = T RUE ; end else Set iter . acti v e = F ALSE ; end else Set iter . acti v e = F ALSE ; return ( iter ) } Class Iterator { variables: value V /* The value on which the index is searched */ boolean active /* Stores the current state oF the iterator (TRUE or ±ALSE)*/ int index /* Index oF the next matching entry (iF active is TRUE) */
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page5 / 12

Then it is enough if the bucket address table has just four...

This preview shows document pages 5 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online