Data Structures · Visualization

Bloom Filter: Add

Bloom Filter

Adding an item to a Bloom filter runs the item through each of the filter's hash functions to get several bit positions, then sets each of those positions to 1 in the bit array. Time: O(k), constant regardless of how many items are already stored. Space: O(1) additional (uses the existing bit array).

Big-O: Space-efficient, no false negatives; possible false positives.

Bloom Filter: Add

Bloom Filter

Adding an item to a Bloom filter runs the item through each of the filter's hash functions to get several bit positions, then sets each of those positions to 1 in the bit array. Nothing is stored about the item itself — only the fact that these specific bits are now 'on'.

How Add Works

  1. Take the item to add.
  2. Run it through each of the k hash functions to get k positions in the bit array.
  3. Set the bit at each of those positions to 1 (if it's already 1, leave it as is).

Add Worked Example

Input: Add 'dog' with hash functions producing positions 2, 5, 8

  1. hash1('dog') = 2 → set bit 2 to 1
  2. hash2('dog') = 5 → set bit 5 to 1
  3. hash3('dog') = 8 → set bit 8 to 1

Output: Bits 2, 5, and 8 are now set to 1

Try your own input
Bloom Filter: Introduction
A compact, probabilistic set: it can tell you an item is "definitely not present" or "probably present", using far less memory than storing every item.
0
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
Active hash bit Bit set to 1 Bit = 0
Bloom Filter: Introduction
Press ▶ Run to watch it step by step.
Python · Bloom Filters in Code
def _hashes(x):
    h = abs(hash(x))
    return [(h >> i) % m for i in range(k)]

def add(x):
    for i in _hashes(x):
        bits[i] = 1      # set each hash bit

# O(k)
# example: add
Input: Add 'dog' with hash functions producing positions 2, 5, 8

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Add Time & Space Complexity

TimeO(k), constant regardless of how many items are already stored
SpaceO(1) additional (uses the existing bit array)

When to Use Add

  • Registering a new item as 'seen' in a deduplication pipeline
  • Marking a URL as processed in a web crawler

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.