Hashing Study Guide
Brute force approach. All data is just a sequence of binary digits (bits). Can treat key as a gigantic number and use it as an array index. Requires exponentially large amounts of memory.
Hashing. Instead of using the entire key, represent entire key by a smaller value. In Java, we hash objects with a hashCode
method (a hash function) that returns an integer representation of the object (a hash code).
Separate chaining. Key-value pairs are stored in a bin of M nodes. Searching or adding a new item both require potentially scanning through entire bin.
Resizing. Understand how resizing may lead to objects moving from one bin to another. Primary goal is so that M is always proportional to N, i.e. maintaining a load factor bounded above by some constant.
Runtime. Cost of an operation is given by the size of the bin that must be examined. Assuming an even distribution across the hash table, we can say that “on average” the runtime for operations is N / M, which is no larger than some constant due to resizing.