Skip to main content

Bloom Filter

SpaceTime
AccessLookupInsertionDeletion
O(n)O(1)

O(k)
• k number of the hash function implemented

O(k)

N/A
• not supported

Definition​

Bloom Filter is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set.

Simplified

Bloom Filter is like a super-efficient memory that can quickly check if an item is in a set. It can say "probably yes" or "definitely no". The "probably yes" can sometimes be wrong, but "definitely no" is always right. For example, your browser uses it to check if a URL is safe.

Practice​

AspectPseudo Code
Insertion
insert(item):
hash_values = get_hash_values(item)
for each val in hash_values:
storage.setValue(val)

get_hash_values(item):
return [hash_function]
May Contain
may_contain(item):
hash_values = get_hash_values(item)
for hash_index from 0 to length(hash_values) - 1:
if storage.get_value(hash_values[hash_index]) != ø:
return False
return True

get_hash_values(item):
return [hash_function]