15. HashTables_outside

And handles collisions by placing an item in the

Info icon This preview shows pages 14–16. Sign up to view the full content.

View Full Document Right Arrow Icon
and handles collisions  by placing an item in the  first available cell of the  series ( i + jd ( k )) mod N for  j = 0, 1, … , N - 1 The secondary hash  function  d ( k )  cannot have  zero values The table size  N  must be a  prime to allow probing of all  the cells Common choice of  compression function for  the secondary hash  function:  d 2 ( k ) = q - k mod q where q < N q  is a prime The possible values for  d 2 ( k )  are   1, 2, … , q ©  2010 Goodrich, Tamassia
Image of page 14

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

View Full Document Right Arrow Icon
Hash Tables 15 Consider a hash  table storing integer  keys that handles  collision with double  hashing N = 13   h ( k ) = k mod 13   d ( k ) = 7 - k mod 7 Insert keys 18, 41,  22, 44, 59, 32, 31,  73, in this order Example of Double Hashing                            0 1 2 3 4 5 6 7 8 9 10 11 12 31   41     18 32 59 73 22 44   0 1 2 3 4 5 6 7 8 9 10 11 12 k h ( k ) d ( k ) Probes 18 5 3 5 41 2 1 2 22 9 6 9 44 5 5 5 10 59 7 4 7 32 6 3 6 31 5 4 5 9 0 73 8 4 8 ©  2010 Goodrich, Tamassia
Image of page 15
Hash Tables 16 Performance of  Hashing In the worst case, searches,  insertions and removals on a  hash table take  O ( n ) time The worst case occurs when  all the keys inserted into the  map collide The load factor  α = n / N affects the performance of a  hash table Assuming that the hash  values are like random  numbers, it can be shown  that the expected number of  probes for an insertion with  open addressing is 1 / (1 - α ) The expected running  time of all the dictionary  ADT operations in a  hash table is  O (1)   In practice, hashing is  very fast provided the  load factor is not close  to 100% Applications of hash  tables: small databases compilers browser caches ©  2010 Goodrich, Tamassia
Image of page 16
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