Hashing

Search algorithms that use hashing work by direct access based on key value. Hashing involves a hash function: a function that transforms the search key into an array index, and a collision-resolution process that deals with the cases where multiple keys are mapped to the same index. For applications where access involves only exact-match queries, hashing is usually the search method of choice because it is extremely efficient when implemented correctly.

Applications

(basically, applications that need search and don't need ordering)

Direct access table

As from the search problem definition, if we have a collection L of n records of the form $(k_1, I_1), (k_2, I_2), ..., (k_n, I_n)$, where $I_j$ is information associated with key $k_j$ from record $j$ for $1\leq j \leq n$. Given a particular key value $K$, the search problem is to locate a record $(k_j, I_j)$ in L such that $k_j = K$ (if one exists). Searching is a systematic method for locating the record (or records) with key value $k_j = K$.
Simplest approach: array of items, where the key key $k_j$ is the index into the array and the information $I_j$ is the value stored in the array.  Main drawbacks: Main advantages: Solutions to drawbacks:

Hash functions

Exercise:
Insert the keys { 7, 18, 2, 3, 14, 25, 1, 11, 12, 1332 }, using open hashing (chaining), in a hash table with $m=11$.
Draw the table (with linked lists where necessary) that you obtain by using the modular hash function h(k) = k mod 11.

Collision resolution

Open hashing

Closed hashing

Hashtable and Hashmap in Java

Class Object & hashCode

Google SparseHash