11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

320 Chap. 9 Searching01000953012330134567987720071057899879Figure 9.3 An illustr<strong>at</strong>ion of open hashing for seven numbers stored in a ten-slothash table using the hash function h(K) = K mod 10. The numbers are insertedin the order 9877, 2007, 1000, 9530, 3013, 9879, <strong>and</strong> 1057. Two of the valueshash to slot 0, one value hashes to slot 2, three of the values hash to slot 7, <strong>and</strong>one value hashes to slot 9.the sum for the integer quantities will typically cause a 32-bit integer tooverflow (thus losing some of the high-order bits) because the resultingvalues are so large. But this causes no problems when the goal is to computea hash function.9.4.2 Open HashingWhile the goal of a hash function is to minimize collisions, some collisions areunavoidable in practice. Thus, hashing implement<strong>at</strong>ions must include some form ofcollision resolution policy. Collision resolution techniques can be broken into twoclasses: open hashing (also called separ<strong>at</strong>e chaining) <strong>and</strong> closed hashing (alsocalled open addressing). 3 The difference between the two has to do with whethercollisions are stored outside the table (open hashing), or whether collisions resultin storing one of the records <strong>at</strong> another slot in the table (closed hashing). Openhashing is tre<strong>at</strong>ed in this section, <strong>and</strong> closed hashing in Section 9.4.3.The simplest form of open hashing defines each slot in the hash table to bethe head of a linked list. All records th<strong>at</strong> hash to a particular slot are placed onth<strong>at</strong> slot’s linked list. Figure 9.3 illustr<strong>at</strong>es a hash table where each slot stores onerecord <strong>and</strong> a link pointer to the rest of the list.3 Yes, it is confusing when “open hashing” means the opposite of “open addressing,” but unfortun<strong>at</strong>ely,th<strong>at</strong> is the way it is.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!