← All Exercises
Bloom Filter False Positive Rate
intermediatejavascript
Background
The closed form tells you how much memory to spend for a target error rate before writing any code, which is how production bloom filters are sized.
Problem
Compute the false positive probability of a bloom filter as (1 - e^(-k*n/m))^k where m is the number of bits, k the number of hash functions, and n the number of inserted items. Output the rate rounded to four decimal places.
Input
A JSON object {"m": number, "k": number, "n": number} of positive integers.Output
A JSON object {"fpr": number} rounded to four decimals.Sample tests
Sample 1
Input: {"m":1024,"k":3,"n":100}Expected: {"fpr":0.0164}Sample 2
Input: {"m":1024,"k":7,"n":100}Expected: {"fpr":0.0073}Sample 3
Input: {"m":1024,"k":3,"n":20}Expected: {"fpr":0.0002}Your solution
Learning objective
Apply the bloom filter sizing formula and interpret hash-count trade-offs.