119 answer let i denote the number of bits of the

Info icon This preview shows pages 6–9. Sign up to view the full content.

View Full Document Right Arrow Icon
11.9 Answer: Let i denote the number of bits of the hash value used in the hash table. Let bsize denote the maximum capacity of each bucket. The pseudocode is shown in Figure 11.2. Note that we can only merge two buckets at a time. The common hash prefix of the resultant bucket will have length one less than the two buckets merged. Hence we look at the buddy bucket of bucket j differing from it only at the last bit. If the common hash prefix of this bucket is not i j , then this implies that the buddy bucket has been further split and merge is not possible. When merge is successful, further merging may be possible, which is handled by a recursive call to coalesce at the end of the function. 11.10 Answer: If the hash table is currently using i bits of the hash value, then maintain a count of buckets for which the length of common hash prefix is exactly i . Consider a bucket j with length of common hash prefix i j . If the bucket is being split, and i j is equal to i , then reset the count to 1. If the bucket is being split and i j is one less that i , then increase the count by 1. It the bucket if being coalesced, and i j is equal to i then decrease the count by 1. If the count becomes 0, then the bucket address table can be reduced in size at that point. However, note that if the bucket address table is not reduced at that point, then the count has no significance afterwards. If we want to postpone the reduction, we have to keep an array of counts, i.e. a count for each value of
Image of page 6

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

View Full Document Right Arrow Icon
Exercises 7 function findIterator(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 = TRUE ; 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 = TRUE ; end else Set iter . acti v e = FALSE ; end else Set iter . acti v e = FALSE ; 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 FALSE)*/ int index /* Index of the next matching entry (if active is TRUE) */ PageID page /* Page Number of the next matching entry (if active is TRUE)*/ function next() { if (active) then begin Set retPage = page ; Set retIndex = index ; if ( index + 1 = page . size ) then begin page = page . P n index = 0 end else index = index + 1; if ( page . K index negationslash= V ) then acti v e = FALSE ; return( retPage , retIndex ) end else return null ; } } Figure 11.1 Pseudocode for findIterator and the Iterator class
Image of page 7
8 Chapter 11 Indexing and Hashing delete (value K l ) begin j = first i high-order bits of h ( K l ); delete value K l from bucket j ; coalesce (bucket j ); end coalesce (bucket j ) begin i j = bits used in bucket j ; k = any bucket with first ( i j
Image of page 8

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern