`hashCode`
==========

Suppose someone has designed a new class and included the method
`public int hashCode` for it. Suppose I use a hash function that maps an
object `x` to index `x.hashCode() % m`. Which of these assumptions do I
need for this to work?

a.  `x.hashCode()` is less than than the length of the array
b.  *the int `x.hashCode()` is never negative*
c.  the `x.hashCode()` values are evenly distributed
d.  different `x`s have different `hashCode`s
e.  All of the above

(f. and that it's consistent! that same object should always return the 
same hash code, and hash codes should not change once computed!)

Collisions
==========

Suppose I have the following list of strings:

`"when" "in" "the" "course"` `"of" "human" "events" "it"`

And I store them in a hash table indexed by the letters `a`, `b`, ...
`z`. Which hash function has no collisions?

a.  a(w) = the first letter of w
b.  b(w) = the second letter of w
c.  c(w) = the last letter of w
d.  *all three cause collisions*

A hash function
===============

Suppose we hashed the 150 students in this class as follows. For student
s, we compute h(s) by adding the ASCII values of the letters in the
student’s last name to get a number n, and then have h(s) = n % 197.
Which of these statements is true?

a.  because 150 \< 197, we will have no collisions
b.  *if s and t have the same last name, h(s) = h(t)*
c.  if s and t have different last names, h(s) ≠ h(t)
d.  because 197 \> 150, there must be collisions

Why no removals?
================

"**If we never remove**, though, we are better off -- we can give up our
search when we reach a null array entry." Why is the phrase in bold
necessary here?

a.  A removal could change the hash function value.
b.  *A removal could create a null entry between the hash function value
    and the entry we stored.*
c.  We only remove items that are in the table.
d.  It’s never allowed to remove from a hash table.

Load factor
===========

What is the worst-case time needed to add, remove, or find an element in
a bucket/chain hash table of size n with n/2 keys in use?

a.  $O(1)$
b.  $O(log\ n)$
c.  *$O(n)$*
d.  $O(n^2)$

