{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture7

# lecture7 - HashTables Dr.YingwuZhu HashTables...

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

Hash Tables Dr. Yingwu Zhu

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

View Full Document
Hash Tables Recall order of magnitude of searches Linear search  O(n) Binary search  O(log 2 n) Balanced binary tree search  O(log 2 n) Unbalanced binary tree can degrade to  O(n)
Hash Tables Sometime faster search is needed Solution: use  hashing Value of key field fed into a hash function Location in a hash table is calculated

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

View Full Document
Hashing Key to hashing The hash function  h(x)
Hash Functions Simple function could be to mod the value  of the key by some arbitrary integer int h(int i) { return i % someInt; } Note the max number of locations in the  table will be same as  someInt Note that we have traded speed for wasted  space Table must be considerably larger than  number of items anticipated

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

View Full Document
Hash Functions Observe the problem with same value returned  by  h(i)  for different values of  i h(i)= i mod 31
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}