15. HashTables_outside

We reinterpret the memory address of the key object

Info icon This preview shows pages 6–11. Sign up to view the full content.

View Full Document Right Arrow Icon
We reinterpret the memory  address of the key object as  an integer Good in general, except for  numeric and string keys Integer cast : We reinterpret the bits of the  key as an integer Suitable for keys of length  less than or equal to the  number of bits of the integer  type (e.g., byte, short, int and  float in C++) Component sum : We partition the bits of  the key into components  of fixed length (e.g., 16 or  32 bits) and we sum the  components (ignoring  overflows) Suitable for numeric keys  of fixed length greater  than or equal to the  number of bits of the  integer type (e.g., long  and double in C++) ©  2010 Goodrich, Tamassia
Image of page 6

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

View Full Document Right Arrow Icon
Hash Tables 7 Hash Codes (cont.) Polynomial accumulation : We partition the bits of the  key into a sequence of  components of fixed length  (e.g., 8, 16 or 32 bits)   a 0 a 1 a n - 1 We evaluate the polynomial p ( z ) = a 0 + a 1 z + a 2 z 2 + + a n - 1 z n - 1 at a fixed value  z , ignoring  overflows Especially suitable for strings  (e.g., the choice  z = 33 gives  at most 6 collisions on a set of  50,000 English words) Polynomial  p ( z )  can be  evaluated in  O ( n )  time  using Horner’s rule: The following  polynomials are  successively computed,  each from the previous  one in  O (1)  time p 0 ( z ) = a n - 1 p i ( z ) = a n - i - 1 + zp i - 1 ( z ) ( i = 1, 2, …, n - 1) We have  p ( z ) = p n - 1 ( z ) ©  2010 Goodrich, Tamassia
Image of page 7
Hash Tables 8 Compression Functions Division : h 2 ( y ) = y mod N The size  N  of the  hash table is usually  chosen to be a prime  The reason has to do  with number theory  and is beyond the  scope of this course Multiply, Add and  Divide (MAD) : h 2 ( y ) = ( ay + b ) mod N a  and  b  are  nonnegative integers  such that   a mod N 0 Otherwise, every  integer would map to  the same value  b   ©  2010 Goodrich, Tamassia
Image of page 8

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

View Full Document Right Arrow Icon
Hash Tables 9 Collision Handling Collisions occur when  different elements are  mapped to the same  cell Separate Chaining:  let  each cell in the table  point to a linked list of  entries that map there Separate chaining is  simple, but requires  additional memory  outside the table 0 1 2 3 4 451-229-0004 981-101-0004 025-612-0001 ©  2010 Goodrich, Tamassia
Image of page 9
Hash Tables 10 Map with Separate Chaining
Image of page 10

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern