Challenge: Implement a Bloom Filter
Task
Swipe to start coding
Implement a BloomFilter class that performs probabilistic membership testing using a bit array and multiple hash functions.
Your implementation must follow these rules:
- The filter uses a bit array of length
size, initialized with zeros. - The filter uses exactly
hash_counthash functions for each inserted item. - The private method
_hashes(item)must produce a list ofhash_countinteger indices, each in the range[0, size). - The
add(item)method must set all corresponding bits for the itemβs hash indices. - The
contains(item)method returns:Trueif all bits for the itemβs hash indices are setFalseotherwise
- The filter may have false positives, but must never produce false negatives (i.e., must never return
Falsefor an item that was previously added).
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 5
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 7.69
Challenge: Implement a Bloom Filter
Swipe to show menu
Task
Swipe to start coding
Implement a BloomFilter class that performs probabilistic membership testing using a bit array and multiple hash functions.
Your implementation must follow these rules:
- The filter uses a bit array of length
size, initialized with zeros. - The filter uses exactly
hash_counthash functions for each inserted item. - The private method
_hashes(item)must produce a list ofhash_countinteger indices, each in the range[0, size). - The
add(item)method must set all corresponding bits for the itemβs hash indices. - The
contains(item)method returns:Trueif all bits for the itemβs hash indices are setFalseotherwise
- The filter may have false positives, but must never produce false negatives (i.e., must never return
Falsefor an item that was previously added).
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 5
single