Lecture14 - Hashing EECS 233-2- Hashing We have learned...

Info iconThis preview shows pages 1–7. 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: Hashing EECS 233-2- Hashing We have learned several data structures that allow us to store and search for data items using their keys Felds. Lists and arrays - linear search complexity Sorted arrays - log complexity for search; linear for inserts Various trees Generally logarithmic time complexity Rich operations: Insert, remove, search (contains), Fnd max/min Can we do better than logarithmic complexity?-3- Chapter 5. Hashing The efFciency of the different data structures and operations: Hash tables and hashing techniques may allow us to search, insert, and delete an item in sub-logarithmic time, for example, O(1) Balanced search tree Binary search tree List (linked list) List (sorted array) List (unsorted array) Insert an item Search for an item Data structure ?-4- Storing Objects in an Array: Keys and Indexes Key: a unique attribute of object Index: a position of object in an array Unsorted arrays: Indexes are independent of keys Searching is dumb and inefFcient Sorted arrays: Indexes are related to keys Searching is smart (no longer blind) and efFcient (logarithmic) The hashing idea: treat the key as an index! Searching is simple and takes almost no time (constant) = genius Example: storing grades about students in this class Give each student a unique key (integer from 1-80). Store the student records in an array, in the position determined by the key We can perform both search/update and insertion in O (1) time (for up to 80 students).-5- Hash Functions Problem with student grades: A student will have different keys in different classes What if we used a social security number? Nice, but a humongous array! In many real-world problems, the key attribute has semantic meaning Cannot be arbitrarily assigned Phone book: key is person s name, not a unique number Web cache: key is a URL To handle these problems, we use a hash function Convert (map) keys into array indices Domain: the keys; range: integers in [0, size-of-array) The word hash: to chop into small pieces (Merriam-Webster) Chopping large domain space into small number of array cells-6- Hash Tables Example: student list Index = SSN mod 80 Problem: multiple keys mapping to the same index Two students with SSN 511-00-0001 and 511-00-0161 511000001 mod 80 = 511000161 mod 80 = 1 We need techniques to handle such cases called collisions The resulting data structure is known as a hash table Hash function Array Procedures and data structures to handle collisions Operations: Insert Remove Contains (search) isEmpty, makeEmplty, etc....
View Full Document

This note was uploaded on 04/07/2008 for the course EECS 233 taught by Professor Rabinovich during the Spring '08 term at Case Western.

Page1 / 22

Lecture14 - Hashing EECS 233-2- Hashing We have learned...

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

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