ArticleslgStudy

computer science

Cuckoo filter

Cuckoo 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 Cuckoo filter rather than just read about it. In short: A cuckoo filter is an space-efficient probabilistic data structure that is used to test whether an element is a member of a set, like a Bloom filter does. False positive matches are possible, but false negatives are not – in other words, a query returns either "possibly in set" or "definitely not in set".

Key takeaways

  • Cuckoo 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 Cuckoo filter to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cuckoo filter from memory before moving on to harder problems.

Reference excerpt

A cuckoo filter is an space-efficient probabilistic data structure that is used to test whether an element is a member of a set, like a Bloom filter does. False positive matches are possible, but false negatives are not – in other words, a query returns either "possibly in set" or "definitely not in set". A cuckoo filter can also delete existing items, which is not supported by Bloom filters. In addition, for applications that store many items and target moderately low false positive rates, cuckoo filters can achieve lower space overhead than space-optimized Bloom filters. Cuckoo filters were first described in 2014.

Algorithm description A cuckoo filter uses a hash table based on cuckoo hashing to store the fingerprints of items. The data structure is broken into buckets of some size b. To insert the fingerprint of an item x, one first computes two potential buckets h1(x) and h2(x) where x could go. These buckets are calculated using the formula

h1(x)=hash(x) h2(x)=h1(x)⊕hash(fingerprint(x)) Note that, due to the symmetry of the XOR operation, one can compute h2(x) from h1(x), and h1(x) from h2(x). As defined above, h2(x)=h1(x)⊕hash(fingerprint(x)); it follows that h1(x)=h2(x)⊕hash(fingerprint(x)). These properties are what make it possible to store the fingerprints with cuckoo hashing. The fingerprint of x is placed into one of buckets h1(x) and h2(x). If the buckets are full, then one of the fingerprints in the bucket is evicted using cuckoo hashing, and placed into the other bucket where it can go. If that bucket, in turn, is also full, then that may trigger another eviction, etc. The hash table can achieve both high utilization (thanks to cuckoo hashing), and compactness because only fingerprints are stored. Lookup and delete operations of a cuckoo filter are straightforward. There are a maximum of two buckets to check by h1(x) and h2(x). If found, the appropriate lookup or delete operation can be performed in O(b) time. Often, in practice, b is a constant. In order for the hash table to offer theoretical guarantees, the fingerprint size f must be at least Ω((log⁡n)/b) bits. Subject to this constraint, cuckoo filters guarantee a false-positive rate of at most ϵ≤b/2f−1.

Comparison to Bloom filters A cuckoo filter is similar to a Bloom filter in that they both are fast and compact, and they may both return false positives as answers to set-membership queries:

Space-optimal Bloom filters use 1.44log2(1/ϵ) bits of space per inserted key, where ϵ is the false positive rate. A cuckoo filter requires (log2(1/ϵ)+1+log2b)/α space per key where α is the hash table load factor, which can be 95.5% based on the cuckoo filter's setting. Note that the information theoretical lower bound requires log2(1/ϵ) bits for each item. Both bloom filters and cuckoo filters with low load can be compressed when not in use. On a positive lookup, a space-optimal Bloom filter requires a constant log2(1/ϵ) memory accesses into the bit array, whereas a cuckoo filter requires at most 2b memory accesses, which can be a constant in practice. Cuckoo filters have degraded insertion speed after reaching a load threshold, when table expanding is recommended. In contrast, Bloom filters can keep inserting new items at the cost of a higher false positive rate before expansion. Bloom filters offer fast union and approximate intersection operations using cheap bitwise operations, which can also be applied to compressed bloom filters if streaming compression is used.

Limitations A cuckoo filter can only delete items that are known to be inserted before. Insertion can fail and rehashing is required like other cuckoo hash tables. Note that the amortized insertion complexity is still O(1). Cuckoo filters require a fingerprint size f of at least Ω((log⁡n)/b) bits. This means that the space per key must be at least (log⁡n)/b bits, even if ϵ is large. In practice, b is chosen to be large enough that this is not a major issue.

References

External links Probabilistic Filters By Example – A tutorial comparing Cuckoo and Bloom filters.

Worked examples

Example 1 — a first encounter with Cuckoo filter

Start with the simplest possible case. Write down what Cuckoo 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 Cuckoo 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 Cuckoo 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 Cuckoo filter

In research
Cuckoo 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 Cuckoo 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
Cuckoo filter is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hash-based data structures, Lossy compression algorithms, Probabilistic data structures, so understanding it makes those chapters shorter.
In everyday life
Look for Cuckoo 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 “Cuckoo filter” →

How to study Cuckoo filter in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cuckoo 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 Cuckoo filter out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cuckoo filter in simple terms?

A cuckoo filter is an space-efficient probabilistic data structure that is used to test whether an element is a member of a set, like a Bloom filter does. False positive matches are possible, but false negatives are not – in other words, a query returns either "possibly in set" or "definitely not i…

Why does Cuckoo 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 Cuckoo 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 Cuckoo filter.

Tags

  • Hash-based data structures
  • Lossy compression algorithms
  • Probabilistic data structures

Keep exploring