Data Structure | Search Method | Time Complexity |
---|---|---|
Unordered array | Linear search | $O(n)$ |
Ordered array | Binary search | $O(\log n)$ |
Array | Random access | $O(1)$ |
Hashing transforms input data into a fixed-size string of bytes.
Digit Addition
cats
is stored at $3 + 1 + 20 + 19 = 43$zzzzzzzzzzz
is stored at $26 * 10 = 260$
Polynomial Hashcode
cats
is stored at $327^3 + 127^2 + 2027^1 + 1927^0 = 60,337$zzzzzzzzzzz
is stored at $2627^9 + 2627^8 + 2627^7 + \dots + 2627^0$
Modulus (%)
$$ \alpha = \frac{n}{N} = \frac{\text{number of items}}{\text{length of the array}}$$
Linear Probing: searches sequentially through the table until an empty slot is found.
Quadratic Probing: searches using a quadratic function.
Double Hashing: