82 1. Streaks

algebra (best performed by a computer algebra package) is as follows.

If p = 1/2 and k is odd, then

rn,k =

1

2n−1

(1 − 4pq)

(k−1)/2

v=0

−1/2

v

(1 −

4pq)−1/2

4pq

1 − 4pq

v

∗

n−1

u=1

u odd

n − 1

u

u/2

(k − 1 − 2v)/2

(1 −

4pq)u/2

∗

4pq

1 − 4pq

(k−1−2v)/2

+

n−1

u=0

u even

n − 1

u

u/2

(k − 1)/2

∗(1 −

4pq)u/2

4pq

1 − 4pq

(k−1)/2

,

while if p = 1/2 and k is even, then

rn,k =

1

2n−1

(4pq)

(k−2)/2

v=0

−1/2

v

(1 −

4pq)−1/2

4pq

1 − 4pq

v

∗

n−1

u=1

u odd

n − 1

u

u/2

(k − 2 − 2v)/2

(1 −

4pq)u/2

∗

4pq

1 − 4pq

(k−2−2v)/2

.

If p = 1/2, the expression for rn,k is much simpler (see Exercise 3).

These expressions were used to generate Figure 1.

We can use the expression for r(x, y, p) to calculate the mean (and

variance) of the distribution. We recall that for fixed n, the mean of

the distribution {rn,k} equals

n

k=1

krn,k .

The value of this sum can be obtained from the generating function

r(x, y, p) by using calculus. If we compute the partial of r(x, y, p)