Hashtables Flashcards
a bad example of a way to hash phone numbers
using the first three digits
a good example of a way to hash phone numbers
last three deigits
what does the hashCode() method return
an int
what is an equality requirement of hash function
x.equals(y)
then x.hashCode() == y.hashCode()
what is highly desirable when it comes to equality and the hashCode() function
if !x.equals(y)
then
x.hashCode != y.hashCode()
what is the deafault implementation of hashCode
using memory address of the object
if a null object is sent into the hashCode function what should be returned
0
if an array is sent into the hashCode function how is it hashed
each array entry is hashed
the int returned must be between
-2^31 and 2^31 -1
how to convert if the key is not in the range
get abs value
what is the uniform hashing assumption
each key is equally likely to has to an integer between 0 and M-1
after how many insertions do we expect two keys in the same index
sq root (pi*M /2)
how many keys do we need to put in for all the indexes to be used
MlgM insertions
what do we expect the height of the most loaded index to ve
logM / loglogM
two methods for dealing with collisions
linear probing
separate chaining
what is a collision
when two keys hash at the same index
what is the separate chaining approach to dealing with collisions
have a linked list in every index of the array
when keys are inserted in the linked list implementation, where are they inserted, at the head or tail
head