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.

Recommend Problems

  1. Q2 from CSE 373 19au MT (Solution)
  2. Q1b, Q1d from CS 61B 16sp MT2 (Solution)
  3. Q2b from CS 61B 17sp MT2 (Solution)
  4. Q2 from CS 61B 18sp MT2 (Solution)
  5. Q5 from CS 61BL 18su MT3 (Solution)