{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture14

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

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

Hashing EECS 233

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

View Full Document
-2- Hashing We have learned several data structures that allow us to store and search for data items using their keys fields. 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), find max/min Can we do better than logarithmic complexity?
-3- Chapter 5. Hashing The efficiency 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 ?

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

View Full Document
-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 inefficient Sorted arrays: Indexes are related to keys Searching is smart (no longer blind) and efficient (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

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

View Full Document
-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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 22

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

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

View Full Document
Ask a homework question - tutors are online