80 likes | 237 Views
Modified. Appendix E-D Hashing – With chaining. Chaining . The chaining method simply treats the hash table conceptually as an array of lists of individual elements Thus each hash value locates a list of all entries that hash to (collide at) that hash location .
E N D
Modified Appendix E-D Hashing – With chaining
Chaining • The chaining method simply treats the hash table conceptually as an array of lists of individual elements • Thus each hash value locates a list of all entries that hash to (collide at) that hash location. • These lists are usually linked (chained) lists. Java Software Structures, 4th Edition, Lewis/Chase
0 1 2 … The chaining method of collision handling Two variants: The table cells can contain the data being stored, or The table cells can contain only head pointers to the lists, with all data being stored in the list nodes. Pros and cons of each variant? N-1 Java Software Structures, 4th Edition, Lewis/Chase
Basic operations • Insert • Find • Delete Lists can be ordered or not Java Software Structures, 4th Edition, Lewis/Chase
Pros of chaining – compared to closed hashing • Hash table does not ever have to be expanded. • Performance degrades more slowly as table fills up. • Fewer (or no) empty table (data) spaces. • Insertion (at the head of list) is simple and takes constant time. • Deletion does not require special treatment. • No clustering Java Software Structures, 4th Edition, Lewis/Chase
Cons of chaining – compared to closed hashing • Extra space used for pointers • Extra time required to allocate list nodes dynamically!!! • Worse locality of reference. Significant if lists get long. Size (and number) of data records must be considered. Java Software Structures, 4th Edition, Lewis/Chase
Chaining using an overflow area Chaining (with simulated links) can be accomplished using an array based structure with an overflow area. Pros and cons?? Java Software Structures, 4th Edition, Lewis/Chase