In the approximate membership problem, we have subset , that supports two operations:
- update():
- query(): return True if else False.
where is the domain that elements belongs to. If , then each representation of takes bits. If , then each needs bits. If is the website address, the length of its elements might is unlimited. Suppose that the average length is about chars, and each char takes bits, then the representation could occupy most bits.
We can solve the membership problem exactly by dictionaries, such as balanced-binary search tree and hash set. This requires space bits. If we allows false positive, we can break this bound.
The idea is to have a bit array with length bits and a pairwise hash family that maps the elements in uniformly at random to each bit in the array. After picking a hash function uniformly at random from , the operation on is performed as follows:
- update():
- query(): return True if else False.
We can only make a mistake if an element and . However, the probability of such event is bounded by
Remark: the accurate probability is given by
To amplify the failure probability to a specified threshold , we can set . A more efficient way is by repetition the array times. Then the overall space usage is
Note that , since it holds that (click to see the plot) for :
When the space usage is
The compress ratio is given by
If we require the failure probability , then , and . That is, we need on bits for each element in , and the average number of operations for updating is , which is about space when , space when , and much less when is the set of possible web addresses.
Remark
There is another implementation that use a single bit array of size but hash functions . We initialization by setting
For :
set for all .
As a result, at most bits of are initialized to be 1.
Now, for an element , we accidentally report it as a member if for all . But the probability that
and
If we use hash functions and set the size , we can also achieve failure probability .
Question to ponder: what is is dynamic?