HashTables

HashTables - 22:17 Hash Tables 1 Hash Tables ∅ ∅ ∅ 1 2 3 4 451-229-0004 981-101-0004 025-612-0001 22:17 Hash Tables 2 Outline and Reading

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 05/06/09 22:17 Hash Tables 1 Hash Tables ∅ ∅ ∅ 1 2 3 4 451-229-0004 981-101-0004 025-612-0001 05/06/09 22:17 Hash Tables 2 Outline and Reading Hash functions and hash tables (§2.5.2) Hash function details Hash code map (§2.5.3) Compression map (§2.5.4) Collision handling (§2.5.5) Chaining Linear probing Double hashing 05/06/09 22:17 Hash Tables 3 Hash Functions and Hash Tables A hash function h maps keys of a given type to integers in a fixed interval [0, N- 1] Example: h ( x ) = x mod N is a hash function for integer keys The integer h ( x ) is called the hash value of key x The goal of a hash function is to uniformly disperse keys in the range [0, N- 1] A hash table for a given key type consists of Hash function h Array (called table) of size N When implementing a dictionary with a hash table, the goal is to store item ( k , o ) at index i = h ( k ) A collision occurs when two keys in the dictionary have the same hash value Collision handing schemes: Chaining : colliding items are stored in a sequence Open addressing : the colliding item is placed in a different cell of the table 05/06/09 22:17 Hash Tables 4 Example We design a hash table for a dictionary storing items (SSN, Name), where SSN (social security number) is a nine-digit positive integer Our hash table uses an array of size N = 10,000 and the hash function h ( x ) = last four digits of x We use chaining to handle collisions ∅ ∅ ∅ ∅ ∅ 1 2 3 4 9997 9998 9999 … 451-229-0004 981-101-0004 200-751-9998 025-612-0001 05/06/09 22:17 Hash Tables 5 Hash Functions A hash function is usually specified as the composition of two functions: Hash code map : h 1 : keys → integers Compression map : h 2 : integers...
View Full Document

This note was uploaded on 03/24/2008 for the course CSC 316 taught by Professor Rhee during the Spring '08 term at N.C. State.

Page1 / 14

HashTables - 22:17 Hash Tables 1 Hash Tables ∅ ∅ ∅ 1 2 3 4 451-229-0004 981-101-0004 025-612-0001 22:17 Hash Tables 2 Outline and Reading

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online