#📝 Note: Bloom Filters

#Overview

A Bloom Filter is a space-efficient, probabilistic data structure used to test whether an element is a member of a set. It is designed to quickly verify membership with minimal memory usage, making it ideal for distributed systems handling large-scale data.

#Core Idea

Element: "url1" ──► Hash1(url1) % m = 2 ──► Set bit 2 to 1
               ──► Hash2(url1) % m = 7 ──► Set bit 7 to 1

Bit Array:
┌───┬───┬───┬───┬───┬───┬───┬───┐
│ 0  0  1  0  0  0  0  1 │
└───┴───┴───┴───┴───┴───┴───┴───┘
  0   1   2   3   4   5   6   7

#Mathematical Foundation

To design a Bloom Filter, we must calculate the optimum array size $m$ and number of hash functions $k$ for a target capacity $n$ (number of elements) and a tolerable false positive probability $p$.

  1. Optimal Number of Hash Functions ($k$):
    $$k = \frac{m}{n} \ln 2 \approx 0.7 \times \frac{m}{n}$$

  2. Optimal Bit Array Size ($m$):
    $$m = - \frac{n \ln p}{(\ln 2)^2} \approx -1.44 \times n \log_2 p$$

Example: For $n = 1\text{ Billion}$ elements and a false positive rate $p = 1%$, we need:

#Why Use Bloom Filters?

#Trade-offs & Limitations