# Lecture 12: Probability Generating Functions

An important application of generating functions to the analysis of algorithms
involves probability generating functions (PGF), which provide a
mechanism for computing averages and variances.
### Background Material

- Lecture 9 on generating functions.
- Lecture 10 on quicksort.
- Elementary probability theory (probability space, mean, variance,
independence) and elementary counting (binomial theorem, binomial
coefficients).
- Chapter 3 (sec. on PGFs) from Flajolet and Sedgewick.

### Reading

Make sure you carefully study the Maple worksheet for this lecture. Additional
handwritten notes are provided.
### Topics

- Definition and examples of PGFs
- Given a random variable X, that takes on only nonnegative integer values
(discrete random variable), the PGF associated with X is the function
P(z) = p_0 + p_1*z + p_2*z^2 + ..., where p_k = Prob(X = k).
- Since the p_k's are probabilities and the only values are the nonnegative
integers P(1) = 1.
- If X and Y are independent random variables with PGFs P and Q, then the PGF
for Prob(X=k) and Prob(Y=j) is equal to P(z)*Q(z).
- Simple example using dice.

- Computing the mean using a PGF.
- Since P'(z) = p_1 + 2*p_2*z + 3*p_3 z^2 + ..., P'(1) = mean(X).

- Computing the variance using a PGF.
- var(X) = sum_k (k-mean(x))^2 * p_k.
- var(X) = P''(1) + P'(1) - P'(1)^2

- Additional examples
- Uniform distribution
- Binomial distribution
- Quicksort distribution

### Maple worksheets and programs

- pgf.mw - Maple worksheet illustrating PGFs.

### Lecture Notes

- pgf.pdf - Handwritten notes from class.

### Assignment

Created: Nov. 29, 2006 by jjohnson@cs.drexel.edu