A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Bloom Filters: Space-Efficient Probabilistic Set Membership

Graduate Depth 88 in the knowledge graph I know this Set as goal
3topics build on this
471prerequisites beneath it
See this on the map →
Hash TablesHash Function Design: Properties and Requirements+1 moreBloom Filters
hashing probabilistic memory

Core Idea

A Bloom filter uses a bit array and k independent hash functions. To insert, set k bits; to test membership, check if all k bits are set. False positives are possible (k bits set by other elements) but false negatives are not. Space is O(n) bits regardless of element size.

How It's Best Learned

Implement a Bloom filter, measure false positive rates with different k and table sizes, and use it for a practical problem (e.g., checking if a URL has been visited). Compare space to a hash set.

Common Misconceptions

Explainer

From your work with hash tables, you know that hashing maps elements to array positions for fast lookup. A hash set can tell you whether an element is a member of a collection in O(1) expected time, but it stores the actual elements — which can be expensive when elements are large (URLs, file paths, cryptographic keys) or when the set contains millions of entries. A Bloom filter trades perfect accuracy for dramatic space savings: instead of storing the elements themselves, it stores only a compact bit array that encodes a probabilistic summary of the set's contents.

Here is how it works. Start with a bit array of m bits, all initialized to 0, and choose k independent hash functions, each of which maps an element to a position in the array. To insert an element, compute all k hash values and set the corresponding k bits to 1. To query whether an element is in the set, compute the same k hashes and check whether all k bits are 1. If any bit is 0, the element was definitely never inserted — you get a guaranteed no. But if all k bits are 1, it might be a true member, or it might be that other insertions coincidentally set those same k bits. This is a false positive. Crucially, false negatives are impossible: if you inserted an element, its k bits are set forever (bits are never cleared back to 0 in a standard Bloom filter).

The false positive rate depends on three parameters: the bit array size m, the number of elements inserted n, and the number of hash functions k. As the array fills up with 1-bits, the probability that a random query finds all k bits set by coincidence increases. The optimal number of hash functions — the one that minimizes false positives — is k = (m/n) · ln 2, which comes from balancing two competing effects: more hash functions means more bits are checked (reducing coincidence), but also more bits are set per insertion (filling the array faster). In practice, with 10 bits per element and 7 hash functions, the false positive rate is about 1%.

The practical applications are everywhere. Web browsers use Bloom filters to check URLs against a list of known malicious sites — the filter fits in memory while the full list would not. Databases use them to avoid expensive disk reads: before searching a file on disk for a key, check the Bloom filter in memory; if it says "no," skip the disk I/O entirely. Distributed systems use them to synchronize data between nodes without transferring entire sets. The pattern is always the same: you have a large set, you need fast membership checks, and you can tolerate a small fraction of false positives because the cost of a false positive (an extra disk read, a redundant network request) is low compared to the cost of storing the full set in memory.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraConditional StatementsDefining and Calling FunctionsFunctions: Decomposing ProblemsFunction Parameters and Argument PassingReturn ValuesVariable ScopeIntroduction to ClassesObjects and InstancesMethods and AttributesAlgorithm Design BasicsTree Structure and Node PropertiesBinary TreesBinary Tree Properties: Height, Balance, CompletenessAmortized AnalysisHash TablesHash Function Design: Properties and RequirementsBloom Filters: Space-Efficient Probabilistic Set Membership

Longest path: 89 steps · 471 total prerequisite topics

Prerequisites (3)

Leads To (1)