CS 310 Unit 10 Collisions and Perfect Hashing

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

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

View Full Document Right Arrow Icon
CS 310 Unit 10 Hash Tables – Collisions and Perfect Hashing Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 If deletion is significant, a doubly linked list is U: Set of all possible keys K: Set of actual keys k HT null k 1 k 7 k 2 data k 6 k 3 k 5 k 1 k 7 k 4
Background image of page 4
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 Expected items per slot ( α ); ½ to be searched α /2 1 + α /2
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Open Addressing Insertion systematically probes the table until an empty slot is found (null or deleted). Search and deletion systematically probe the hash table until the target element is found or a null slot is found The hash function depends on both the key and probe number: the key k comes from the universe of keys, U the probe number i iterates on the set of hashes: {0, 1, …, m–1}.
Background image of page 7

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

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

This note was uploaded on 06/09/2008 for the course CS 310 taught by Professor Furmanhaddix during the Spring '08 term at Minnesota State University, Mankato.

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 Right Arrow Icon
Ask a homework question - tutors are online