{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS 310 Unit 10 Collisions and Perfect Hashing

# CS 310 Unit 10 Collisions and Perfect Hashing - CS 310 Unit...

This preview shows pages 1–8. Sign up to view the full content.

CS 310 Unit 10 Hash Tables – Collisions and Perfect Hashing Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008

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

View Full Document
CS 310 Hash Tables Objectives Unit 9 Dynamic Sets Direct Addressing Hashing Functions Unit 10 Collisions Chaining Load Factors Open Addressing Linear Probing Quadratic Probing Double Hashing Perfect Hashing Text, Chapter 10
Collisions Happens when two keys hash to the same slot h(k 1 ) == h(k 2 ) Always possible when the set of possible keys is larger than the number of slots Always happens if set of actual keys (n) larger than the number of slots (m) Increased likelihood as number of keys, n, approaches the number of slots, m. Two common methods of dealing with collisions are chaining and open

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

View Full Document
Chaining A common implementation of chaining is to make the hash table an array of pointers to linked lists: For most applications, building forward is adequate Singly linked lists are good, unless deletion is required If deletion is significant, a doubly linked list is preferable U: Set of all possible keys K: Set of actual keys k 3 HT null k 4 k 5 k 1 k 2 k 6 null null null k 7 k 2 data null k 6 data k 3 data k 5 data null k 1 data null k 7 data null null k 4 data
Load Factors and Performanc e A key metric in hashing is the load factor α α represents the ratio of keys to slots ( α = n/m) α is important in analyzing expected performance of hash table operations If we assume that hashing is an O(1) activity, than the principal performance factor in using hashing is how many comparisons we need to make. Insertion using Chaining: Comparison based on hash table 1 Average number of items per slot α Total expected time 1 + α Unsuccessful Search using Chaining (Search and Deletion) Same analysis as above 1 + α Successful Search using Chaining (Search and Deletion) Expected items per slot ( α ); ½ to be searched α /2 Total expected time 1 + α /2 Conclusion: All of the above operations are O(1 + α )

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

View Full Document
Open Addressing In open addressing, all items are stored in the hash table This means that α 1 Open addressing requires additional probes A probe is an examination of a slot In chaining, our probe is application of a hash function In open addressing, a secondary hash function is often used Our problem is that we must have a sequence of probes for each key: h(k, 0), h(k, 1), h(k, 2), … A sequence of probes should be a permutation of the m slots, so that potentially all slots are examined no slot is examined more than once
Open Addressing Insertion systematically probes the table until an empty slot is found (null or deleted).

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 30

CS 310 Unit 10 Collisions and Perfect Hashing - CS 310 Unit...

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

View Full Document
Ask a homework question - tutors are online