lecture7 - HashTables Dr.YingwuZhu HashTables

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

View Full Document Right Arrow Icon
Hash Tables Dr. Yingwu Zhu
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Hashing Key to hashing The hash function  h(x)
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Hash Functions Observe the problem with same value returned  by  h(i)  for different values of  i h(i)= i mod 31
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CSSE 250 taught by Professor Dr.yingwuzhu during the Spring '11 term at UH Clear Lake.

Page1 / 17

lecture7 - HashTables Dr.YingwuZhu HashTables

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