Lect10 - Hashing Techniques 1 Hashing Techniques Several...

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

View Full Document Right Arrow Icon
1 Hashing Techniques
Background image of page 1

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

View Full Document Right Arrow Icon
2 Hashing Techniques Several ADTs for storing and retrieving data were discussed – Linear Lists, Binary Trees, BSTs, AVL Trees. An important operation Findkey () has a time complexity: O(n) in Lists, O(n) in Binary Trees, O(log n) in BSTs, O(log n) in AVL trees. Can Findkey () be implemented with a time complexity better than O(log n)? – With Hash Tables it is possible to implement Findkey () with O(1) time complexity.
Background image of page 2
3 Hashing Techniques A hash table for a given key type consists of Hash function Array (called table) of size N Hash function maps a key to a location in the table. Hash functions can be of two types: Perfect hash functions Imperfect hash functions
Background image of page 3

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

View Full Document Right Arrow Icon
4 Hashing Techniques Perfect hash functions map a key to the ‘exact address’ in the hash table. The key can be found at the address without additional search. Perfect hash functions are hard to determine and compute. exact address f (key) Imperfect hash functions map a key to a ‘home address’ in the hash table. The key may not be at the address and finding it may require additional search. Imperfect hash functions are easy to determine and compute. home address H(key)
Background image of page 4
5 Hashing Techniques In the hash table the data elements are scattered randomly throughout the hash table – there is no first, root or last element. Hash tables are suitable for implementing sets but not linear or hierarchical structures.
Background image of page 5

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

View Full Document Right Arrow Icon
6 Hash Table: Example Table Size, N = 7. Hash Function: H(key) = key mod 7. 0 1 2 3 6 empty empty empty empty empty 4 5 empty empty Initially Hash Table is empty
Background image of page 6
7 Hash Table: Example Insertions: keys 374, 1091, 911are inserted. H(374) = 374 mod 7 = 3 H(1091) = 1091 mod 7 = 6 H (911) = 911 mod 7 = 1 0 1 2 3 6 empty empty 1091 911 empty 4 5 374 empty
Background image of page 7

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

View Full Document Right Arrow Icon
8 Hash Table: Example Retrievals: keys 374 and 740 are retrieved H(374) = 374 mod 7 = 3 Table address 3 contains the key. H(740) = 740 mod 7 = 5 Table address 5 is empty. 0 1 2 3 6 empty empty 1091 911 empty 4 5 374 empty
Background image of page 8
Hash Table: Example Insertions: key 227 is to be inserted. H(227) = 227 mod 7 = 3 Hash functions tells us store it in home address 3 but there is already a key stored in home address 3. This called a collision . Since table is not empty the collided key 227
Background image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 35

Lect10 - Hashing Techniques 1 Hashing Techniques Several...

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

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