ArticleslgStudy

computer science

Counting Bloom filter

Counting Bloom filter is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Counting Bloom filter rather than just read about it. In short: A counting Bloom filter (CBF) or spectral Bloom filter is a probabilistic data structure that is used to test whether the number of occurrences of a given element in a sequence exceeds a given threshold. As a generalized form of the Bloom filter, false positive matches are possible, but false negatives are not – in other words, a query returns either "possibly bigger or equal than the threshold" or "definitely small…

Key takeaways

  • Counting Bloom filter belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Counting Bloom filter to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Counting Bloom filter from memory before moving on to harder problems.

Reference excerpt

A counting Bloom filter (CBF) or spectral Bloom filter is a probabilistic data structure that is used to test whether the number of occurrences of a given element in a sequence exceeds a given threshold. As a generalized form of the Bloom filter, false positive matches are possible, but false negatives are not – in other words, a query returns either "possibly bigger or equal than the threshold" or "definitely smaller than the threshold".

Algorithm description Most of the parameters are defined same with Bloom filter, such as m, k. m is the number of counters in counting Bloom filter, which is expansion of m bits in Bloom filter. An empty counting Bloom filter is a m counters, all set to 0. Similar to Bloom filter, there must also be k different hash functions defined, each of which maps or hashes some set element to one of the m counter array positions, generating a uniform random distribution. It is also similar that k is a constant, much smaller than m, which is proportional to the number of elements to be added. The main generalization of Bloom filter is adding an element. To add an element, feed it to each of the k hash functions to get k array positions and increment the counters 1 at all these positions. To query for an element with a threshold θ (test whether the count number of an element is smaller than θ), feed it to each of the k hash functions to get k counter positions. If any of the counters at these positions is less than θ, the count number of element is definitely less than θ – if it were more and equal, then all the corresponding counters would have been greater or equal to θ. If all are greater or equal to θ, then either the count is really greater or equal to θ, or the counters have by chance been greater or equal to θ. If all are greater or equal to θ even though the count is smaller than θ, this circumstance is defined as false positive. This also should be minimized like Bloom filter. About hashing problem and advantages, see Bloom filter. A counting Bloom filter is essentially the same data structure as count–min sketches, but are used differently.

Potential for false negatives Several implementations of counting bloom filters allow for deletion, by decrementing each of the k counters for a given input. This will introduce the probability of false negatives during a query if the deleted input has not previously been inserted into the filter. Guo et al. present the problem in great detail, and provide heuristics for the parameters m, k, and n which minimize the probability of false negatives.

Probability of false positives The same assumptions in Bloom filter, which hash functions make insertions uniform random, is also assumed here. In the m pots, kn balls are inserted randomly. So the probability of one of counter in counting Bloom filter counts l is b(l,kn,1m)=(knl)(1m)l(1−1m)kn−l, where b is binomial distribution. A counting Bloom filter determines an element is greater or equal to θ when the corresponding k counters are greater or equal to θ. Therefore, the probability that counting Bloom filter determines an element is greater or equal to θ is pfp(θ,k,n,m)=(1−∑l<θb(l,kn,1m))k. This is different from formal definition of false positive in counting Bloom filter. However, following the assumption in Bloom filter, above probability is defined as false positive of counting Bloom filter. If θ=1, the equation becomes false positive of Bloom filter.

Optimal number of hash functions For large but fixed n and m, the false positive decreases from k=1 to a point defined kopt, and increases from koptto positive infinity. Kim et al. (2019) shows numerical values of koptwithin 1≤θ≤30. For θ>30 they suggested using the floor or ceiling of mn(0.2037θ+0.9176).

Variants

Invertible Bloom filter An invertible Bloom filter (IBF) is a variant of the counting Bloom filter that allows for listing of the remaining element, given there are not too may of them. There is, however, a small chance that multiple hash collisions can render a element unrecoverable. Like a CBF, an IBF consists of a hash table B which uses k hash functions h1...hk and stores a counter in each of its m cells. Alongside each counter, it also stores a sum of elements and a sum of element hashes using a new hash function g. There is also a second hash table C to recover elements that could not be recovered using B, which also has m cells but only uses two hash functions f1 and f2. The total number of elements (n) is also stored. To insert an element x, do the following:

increment n for each 1 ≤ i ≤ k do increment B[hi(x)].count add x to B[hi(x)].idSum add g(x) to B[hi(x)].hashSum for each i in {1, 2} do increment C[fi(x)].count add x to C[fi(x)].idSum add g(x) to C[fi(x)].hashSum

Likewise, to remove an element x, do the following:

decrement n for each 1 ≤ i ≤ k do decrement B[hi(x)].count subtract x from B[hi(x)].idSum subtract g(x) from B[hi(x)].hashSum for each i in {1, 2} do decrement C[fi(x)].count subtract x from C[fi(x)].idSum subtract g(x) from C[fi(x)].hashSum

Repeated insertions and removals can be simplified. A cell is considered "pure" if it contains only one distinct element x, which can be checked using g(B[i].idSum/B[i].count) = B[i].hashSum/B[i].count. If a cell is pure, then x can be recovered by dividing the idSum by the count. To list the remaining elements ("stragglers"), do the following:

while there is a pure cell i in B do let x := B[i].idSum/B[i].count if B[i].count > 0 then (this is a good element) output x for 1 ≤ i ≤ B[i].count do remove element x from B and C else (this is a false delete) for 1 ≤ i ≤ -B[i].count do insert element x into B and C if n ≠ 0 then (there are conflicts in B) repeat the above while loop, but swap B and C

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Counting Bloom filter

Start with the simplest possible case. Write down what Counting Bloom filter claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Counting Bloom filter before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Counting Bloom filter ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Counting Bloom filter

In research
Counting Bloom filter appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Counting Bloom filter in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Counting Bloom filter is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hash-based data structures, so understanding it makes those chapters shorter.
In everyday life
Look for Counting Bloom filter outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Counting Bloom filter” →

How to study Counting Bloom filter in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Counting Bloom filter means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Counting Bloom filter out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Counting Bloom filter in simple terms?

A counting Bloom filter (CBF) or spectral Bloom filter is a probabilistic data structure that is used to test whether the number of occurrences of a given element in a sequence exceeds a given threshold. As a generalized form of the Bloom filter, false positive matches are possible, but false negat…

Why does Counting Bloom filter matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Counting Bloom filter?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Counting Bloom filter.

Tags

  • Hash-based data structures

Keep exploring