Bloom Filter is a space-efficient probabilistic data structure for testing set membership.
Key Characteristics:
How it Works: To add an element, hash it with k different hash functions to get k array positions, then set those bits to 1. To test membership, hash the element and check if all k bits are set to 1.
False Positive Rate: Probability ≈ (1 - e^(-kn/m))^k, where k = hash functions, n = elements added, m = bit array size.
Operation | Time |
---|---|
Add | O(k) |
Test | O(k) |
Space | O(m) |
k = hash functions, m = bit array size
Optimal hash functions: k = (m/n) × ln(2)
Optimal bit array size: m = -n × ln(p) / (ln(2))²
n = expected elements, p = desired false positive rate