Practice Discrete Math

Algorithms / Indicator Variables

Least You Need to Know: Indicator Variables and Linearity of Expectation

Indicator variables turn counting questions into algebra. Define one indicator for each event of interest, sum them to count how many events occur, and then use linearity of expectation to compute the expected count. The key advantage is that independence is often unnecessary.

The least you need to know

Key notation

I_E indicator variable of event `E`, equal to 1 if `E` happens and 0 otherwise
E[I_E] probability that event `E` happens
linearity of expectation expectation of a sum equals the sum of expectations

Tiny worked example

  • Let `X` be the number of collisions in a hash table.
  • Define `I_{i,j}=1` when keys `i` and `j` collide, else 0.
  • Then `X = sum I_{i,j}` over all pairs.
  • Taking expectations gives `E[X] = sum E[I_{i,j}] = sum P(i and j collide)`.

Common mistakes

How to recognize this kind of problem

Start practice