Comparing two huge sets element by element is slow, and comparing millions of pairs is hopeless. MinHash shrinks each set to a tiny signature of k numbers, then estimates similarity by comparing signatures. The magic property: for a single hash function, the probability that the two sets share the same minimum hash value is exactly their Jaccard similarity — the fraction of elements they have in common. Average over k hashes and you get a fast, accurate estimate. Add hashes and watch the estimate home in on the true overlap.
signature of k numbers · P(min matches) = Jaccard similarity · near-duplicate detection at scale
Jaccard similarity
|A ∩ B| / |A ∪ B| — the fraction of the combined elements that both sets share.
min-hash
For one hash function, the minimum hash value over all of a set’s elements.
signature
A set’s k min-hash values — a tiny fixed-size fingerprint, regardless of set size.
estimate
The fraction of the k signature positions where two sets’ min-hashes agree.
minhash.js — k minima, one similarity
Ready
Two sets with some overlap. Their true Jaccard similarity is fixed. Each Add hash computes one min-hash for each set: if the two minima match, that’s a vote for similarity. The match rate estimates Jaccard.
0
hashes (k)
–
estimate
0.33
true Jaccard
How it works
Here is why one min-hash matches with probability exactly the Jaccard similarity. Imagine hashing every element of the union A ∪ B and asking which element gets the smallest hash. That “winner” is equally likely to be any element of the union. The two sets share the same minimum if and only if that winning element lies in the intersection A ∩ B. So the match probability is |A ∩ B| / |A ∪ B| — the Jaccard similarity, by definition. Each hash is one Bernoulli trial with that success probability; averaging k of them estimates it.
1
Pick a hash function
Choose a hash that maps every possible element to a number, effectively a random permutation of the elements.
2
Take each set’s minimum
Hash every element of set A and keep the smallest value; do the same for set B. These are the two sets’ min-hashes for this hash function.
3
A match is a vote
If A’s minimum equals B’s minimum, the winning element is in the intersection — count it as a match. The chance of that is exactly the Jaccard similarity.
✓
Average over k hashes
Repeat with k independent hashes to build k-number signatures. The fraction of positions where the signatures agree estimates the Jaccard similarity, with accuracy improving as k grows.
Signature size
k numbers
P(match)
Jaccard
Estimate error
~1/√k
Used in
dedup, LSH
The code
# estimate Jaccard(A, B) with k min-hashesdef minhash_estimate(A, B, hashes):
matches = 0
for h in hashes: # k independent hash functions
min_a = min(h(x) for x in A) # set A's min-hash
min_b = min(h(x) for x in B) # set B's min-hashif min_a == min_b:
matches += 1 # the winner is in A ∩ Breturn matches / len(hashes) # ≈ |A∩B| / |A∪B|
Quick check
1. What does MinHash estimate?
MinHash estimates the Jaccard similarity |A∩B|/|A∪B|. The fraction of signature positions where two sets’ min-hashes agree converges to that value.
2. Why does one min-hash match with probability equal to the Jaccard similarity?
The element with the smallest hash over A∪B is uniformly random among union elements. The two sets share that minimum exactly when the winner is in A∩B, so the match probability is |A∩B|/|A∪B| — the Jaccard.
3. How does the estimate improve as you add more hashes?
Each hash is an independent Bernoulli trial with success probability equal to the Jaccard. Averaging k of them reduces the standard error like 1/√k, so more hashes tighten the estimate.
FAQ
What is MinHash?
A technique for quickly estimating the Jaccard similarity of two sets. Each set is represented by a signature of k values, each the minimum of a hash over the set’s elements. The fraction of signature positions where two sets agree estimates their Jaccard similarity — far faster than comparing elements directly.
What is Jaccard similarity?
The size of the intersection divided by the size of the union: |A∩B| / |A∪B|. It ranges from 0 (nothing shared) to 1 (identical) and measures the fraction of combined elements the two sets share.
How is MinHash used with Locality-Sensitive Hashing (LSH)?
MinHash produces each item’s signature; LSH buckets signatures so similar items likely collide, avoiding all-pairs comparison. The signature is split into bands, and items sharing any band become candidate matches — together they scale near-duplicate detection to billions of items.
Where is MinHash used in practice?
Near-duplicate web page and document detection (search index dedup), plagiarism detection, clustering, recommendation/collaborative filtering, and dataset deduplication — anywhere you must find similar items in a huge collection where exact pairwise comparison is too costly.
The picture: who holds the minimum
One hash function, applied to every element of both sets (values scaled to 0–999). Each set keeps only its smallest value. Green means both sets chose the same element, which can only be 4, 5 or 6; red means the minima differ. Repeating this with new seeds gives one vote per hash.
Worked example, step by step
Take A = {1, 2, 3, 4, 5, 6} and B = {4, 5, 6, 7, 8, 9}. The intersection has 3 elements and the union has 9, so the true Jaccard similarity is 3/9 = 0.333. Hash number s is FNV-1a over the decimal digits of the element, seeded with s, finished with the murmur3 mixing steps. For each of 8 seeds, find the element each set gives the smallest hash, and count a vote when the two elements agree.
Hash
Min of A (element)
Min of B (element)
Match?
Running estimate
1
86222693 (2)
30487999 (7)
no
0.000
2
760498317 (5)
760498317 (5)
yes
0.500
3
2006135258 (4)
1837757736 (7)
no
0.333
4
263244247 (6)
263244247 (6)
yes
0.500
5
419643658 (6)
419643658 (6)
yes
0.600
6
535183731 (3)
599835869 (4)
no
0.500
7
986628126 (6)
986628126 (6)
yes
0.571
8
565208416 (3)
976527643 (8)
no
0.500
4 of 8 hashes matched, so the signature estimate is 4/8 = 0.500 against a true 0.333. Every match falls on an element of the intersection: when A and B agree, the shared minimum is always 4, 5 or 6. Every miss is a hash where the overall winner sat in only one set (an element from 1–3 or 7–9). The running estimate in the last column wanders, and with only 8 votes it has to: each vote is a coin flip with probability 0.333. The next section measures how fast that settles.
Complexity and trade-offs
Case
Time
Space
Why
MinHash signature
O(k · |S|) to build
O(k) per set
Built once per set. Two signatures compare in O(k), whatever the set sizes.
Exact Jaccard with hash sets
O(|A| + |B|) per pair
O(|A| + |B|)
Exact, but touches every element of both sets for every pair.
All pairs of n sets, exact
O(n² · set size)
O(n · set size)
Quadratic in the number of documents.
All pairs of n sets, signatures
O(n² · k)
O(n · k)
Still quadratic in n, but the constant no longer depends on set size.
Signatures + banding (LSH)
about O(n · k) to bucket
O(n · k)
Only sets sharing a band are compared; trades recall of borderline pairs for speed.
Accuracy costs signature length. On the page's sets (true 0.333), 2,000 independent runs per row, each with fresh seeds:
k = 8 gives mean 0.338, standard deviation 0.168 (formula √(J(1−J)/k) = 0.167); k = 32: 0.335, 0.084 (0.083); k = 128: 0.336, 0.041 (0.042); k = 512: 0.334, 0.021 (0.021). The estimate is unbiased, and the error falls as 1/√k: four times the signature for half the error. Signatures only beat exact comparison when sets are large or when each signature is reused across many comparisons. For two 6-element sets, comparing them directly is cheaper than 128 hashes.
Common mistakes
Reusing one hash for all k positions
If every position uses the same function, all k votes are the same vote. On the page's sets hash 1 gives no match, so a signature of 8 copies of it reports 0.000; had it matched, it would report 1.000. Across 2,000 different seeds, 31.9% matched (the truth is 33.3%), so a single hash is right only on average, never in one run.
Misaligning signature positions
Position i of one signature must be compared with position i of the other, built with the same seed. Build B's signature with seeds shifted by one and the estimate of the page's sets with k = 128 is 0.000 instead of 0.320, because the votes now compare unrelated hashes.
Using a tiny k and trusting it
With k = 8, 45.8% of runs on the page's sets land more than 0.1 away from the truth. With k = 128 that falls to 1.4%. Pick k from the error you can tolerate, using √(J(1−J)/k).
Treating equal signatures as equal sets
A and A plus one extra element have Jaccard 0.857. With k = 8, all eight positions agree in 28.6% of runs, so identical signatures do not prove identical sets. Verify candidates exactly before acting on a match.
Expecting counts to matter
MinHash estimates set similarity, so repeats are invisible: A with every element repeated three times gives the identical signature. If frequency matters, use a weighted variant or add the count into the element (for example "x#1", "x#2").
Where this shows up
Near-duplicate documents
Break each document into overlapping word groups (shingles), treat them as a set, and compare signatures. Pages that differ by a timestamp or a footer stay highly similar, and the pairs worth comparing can be found without reading every document against every other.
Deduplicating training data
Large text corpora are often filtered for near-duplicates before training. With 1,000,000 documents, exact pairwise comparison would be 499,999,500,000 pairs; banding signatures avoids nearly all of them.
Recommendations and similar users
Two users who liked overlapping sets of items have a high Jaccard similarity. A signature per user lets a service find neighbours without scanning every user's full history.
Clustering and sketching sets
Any task that asks "how much do these two collections overlap?" at scale, such as tags, links, or sets of visited pages, can store k numbers per collection instead of the collection.
SOLVE IT YOURSELF
Solve it: compare two sets without comparing them
Reduce a million-element set to 128 numbers, then estimate how similar any two sets are by counting how many of those numbers match. The probability of a match is the Jaccard similarity. Python or TypeScript.
YOUR TASK
Implement signature(items, num_hashes) — the minimum hash value under each of num_hashes independent hashes — and estimate_jaccard(sig_a, sig_b), the fraction of positions where the two signatures agree.
HINTS — 6 IDEAS
For each hash function, take the minimum over every element of the set. That single number is the signature slot.
Why it works: under a random hash, every element is equally likely to be the smallest. So the minimum agrees for two sets exactly when the overall smallest element is in both — which happens with probability |A∩B| / |A∪B|, the Jaccard similarity.
So estimating similarity is just counting matching slots. No intersection is ever computed.
More hashes means a tighter estimate — the error shrinks as 1/√k, so 128 slots give roughly ±4%.
The hashes must be independent, and each must avalanche. A weak hash makes the minima correlated and the estimate quietly wrong.
Identical sets always score exactly 1.0 and disjoint sets almost always 0.0 — the tests check both, plus accuracy against a real Jaccard in between.