Data structures

Bloom Filter

Add keys to a bit array with several hash functions. Membership tests are fast, but false positives are possible and deletion is not supported.

5 minLevel 3/3The interactive stage stays ad-free.
Keys4Bits set12 / 24Fill ratio50%
00
10
20
31
40
50
61
71
80
91
101
110
120
131
140
150
161
170
181
191
201
211
221
230
applebananacherrydate

Cyan bits are set by at least one key; highlighted bits are checked by the current query. If any queried bit is 0, the key is definitely absent. All bits set means “probably present,” because other keys may have set those bits.

What you are seeing

1

A Bloom filter is a bit array plus several independent hash functions.

2

Inserting a key sets every bit at its hash positions. Querying checks whether all those bits are set.

3

If any bit is 0, the key is definitely absent. If all bits are 1, it is probably present — but not guaranteed.

Why it matters

Bloom filters save memory in databases, caches, spelling correction, and network security by answering “definitely not present” very cheaply.

Complexity & details

Insert/lookup: O(k) for k hash functions. Space: O(m) bits, independent of key length.

Frequently asked questions

Why can’t Bloom filters delete?+

Clearing bits for one key could clear bits shared with other keys, creating false negatives. Counting Bloom filters solve this with counters.

What controls the false-positive rate?+

The number of bits, number of inserted keys, and number of hash functions. More bits per key and an optimal k reduce false positives.