# 10 - Hash Tables Data Structures and Algorithms Andrei...

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

Hash Tables Data Structures and Algorithms Andrei Bulatov

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

View Full Document
Algorithms – Hash Tables 10-2 The Dictionary Problem We have a dictionary Each entry of the dictionary consists of a key , a word, and an article explaining the word We to perform several simple operations with dictionary: search insert delete How should store the dictionary to perform those operations most efficiently? Goal: perform search in O(1) time, at least on average
Algorithms – Hash Tables 10-3 Straightforward Approaches We can try lists: Then search takes O(n) time Binary trees, heaps: Search takes O(log n) time

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

View Full Document
Algorithms – Hash Tables 10-4 Direct Access Tables Create an array with entries indexed by all possible keys Word Antidisestablishmentarianism contains 28 letters all possible keys key article key article key article actually used keys
Algorithms – Hash Tables 10-5 Hashing The idea is - to have a smaller, more realistic table - to address an entry use not the key k itself, but a certain function h(k) computed using k The function used is called hash function, and the table --- hash table Let U be the set (universe) of all possible keys, and m is the desired size of the table Then h: U {0, …, m – 1} Key k (or the whole element) hashes to h(k) h(k) is the hash value of k

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

View Full Document
Algorithms – Hash Tables 10-6 Collisions Everything is perfect as long as the hash values of all keys are different This is called a collision 1 k 2 k 3 k ) ( 1 k h ) ( 2 k h ) ( 3 k h ) ( 4 k h = 4 k
Algorithms – Hash Tables 10-7 Chaining In case of collision create a list of elements with the same hash value 1 k 2 k 3 k 4 k 6 k 5 k key article next key article next key article next key article next key article next key article next

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

View Full Document
Algorithms – Hash Tables 10-8 Analysis We estimate time needed for searching in a hash table
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 19

10 - Hash Tables Data Structures and Algorithms Andrei...

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

View Full Document
Ask a homework question - tutors are online