Computer ScienceData StructuresMedium

Bloom Filter

Also known as:Probabilistic setApproximate membership structure

A Bloom filter is a space-efficient probabilistic data structure used to test whether an element is a member of a set. It can yield false positives (reporting an element is present when it is not) but never false negatives (it will never miss a true member). It works by hashing elements into a bit array using multiple hash functions. Bloom filters are used in databases, web caches, network routers, and spell checkers where memory efficiency is critical and occasional false positives are tolerable.

Key Formula

P_fp = (1 - e^(-k*n/m))^k

LaTeX: P_{fp} = \left(1 - e^{-kn/m}\right)^k

SymbolMeaningUnit
P_fpProbability of a false positivedimensionless (0 to 1)
kNumber of hash functionscount
nNumber of elements insertedcount
mSize of the bit array (number of bits)bits
eEuler's number (≈ 2.718)dimensionless

Worked Example

Problem

A Bloom filter uses m = 1000 bits, k = 7 hash functions, and has n = 100 elements inserted. What is the probability of a false positive?

Solution

Step 1: Identify variables: m = 1000, k = 7, n = 100. Step 2: Compute the exponent: -k*n/m = -(7 × 100) / 1000 = -700 / 1000 = -0.7. Step 3: Compute e^(-0.7) ≈ 0.4966. Step 4: Compute 1 - e^(-0.7) = 1 - 0.4966 = 0.5034. Step 5: Raise to the power k: (0.5034)^7 ≈ 0.00819.

Answer

False positive probability ≈ 0.82% (approximately 1 in 122 queries will be a false positive)

Bloom Filter vs Hash Set: Trade-offs

PropertyBloom FilterHash SetNotes
Space per elementVery low (~10 bits)High (pointer + data)Bloom filter wins for large n
False positivesPossible (tunable)NoneTrade-off for space savings
False negativesNeverNeverBoth are reliable for misses
Deletion supportNo (standard)YesCounting Bloom filter adds deletion
Lookup timeO(k) — very fastO(1) amortizedk is small constant

Interactive Tools

Bloom Filter Calculator

Open Tool

Brilliant.org — Bloom Filters

Open Tool

WolframAlpha — Probability Calculations

Open Tool
A Bloom filter bit array showing three elements mapped by multiple hash functions

Wikimedia Commons, CC BY-SA

Related Terms

The Bloom filter was conceived by Burton Howard Bloom in 1970, and is named after him. The word "filter" reflects its function of filtering membership queries. Bloom published it in a paper titled "Space/Time Trade-offs in Hash Coding with Allowable Errors" in the Communications of the ACM.

bloom-filterprobabilistichashingspace-efficientdata-structuremembership-testing