Docsity

Probability of Students Receiving Their Own Homework in a Permutation of Classwork - Prof., Study notes of Computer Science

Toggle sidebar
bg1
CS 70 Discrete Mathematics for CS
Spring 2007 Luca Trevisan Lecture 19
Random Variables and Expectation
Question: The homeworks of 20 students are collected in, randomly shuffled and returned to the students.
How many students receive their own homework?
To answer this question, we first need to specify the probability space: plainly, it should consist of all 20!
permutations of the homeworks, each with probability 1
20! . [Note that this is the same as the probability
space for card shuffling, except that the number of items being shuffled is now 20 rather than 52.] It helps
to have a picture of a permutation. Think of 20 books lined up on a shelf, labeled from left to right with
1,2,...,20. A permutation
π
is just a reordering of the books, which we can describe just by listing their
labels from left to right. Let’s denote by
π
ithe label of the book that is in position i. We are interested in the
number of books that are still in their original position, i.e., in the number of i’s such that
π
i=i. These are
often known as fixed points of the permutation.
Of course, our question does not have a simple numerical answer (such as 6), because the number depends on
the particular permutation we choose (i.e., on the sample point). Let’s call the number of fixed points X. To
make life simpler, let’s also shrink the class size down to 3 for a while. The following table gives a complete
listing of the sample space (of size 3! =6), together with the corresponding value of Xfor each sample
point. [We use our bookshelf convention for writing a permutation: thus, for example, the permutation 312
means that book 3 is on the left, book 1 in the center, and book 2 on the right. You should check you agree
with this table.]
permutation
π
value of X
123 3
132 1
213 1
231 0
312 0
321 1
Thus we see that Xtakes on values 0, 1 or 3, depending on the sample point. A quantity like this, which
takes on some numerical value at each sample point, is called a random variable (or r.v.) on the sample
space.
Definition 19.1 (random variable): A random variable Xon a sample space
Ω
is a function that assigns
to each sample point
ω
∈
Ω
a real number X(
ω
).
Until further notice, we’ll restrict out attention to discrete random variables: i.e., their values will be integers
or rationals, rather than arbitrary real numbers.
The r.v. Xin our permutation example above is completely specified by its values at all sample points, as
CS 70, Spring 2007, Lecture 19 1
pf3
pf4
pf5

Partial preview of the text

Download Probability of Students Receiving Their Own Homework in a Permutation of Classwork - Prof. and more Study notes Computer Science in PDF only on Docsity!

CS 70 Discrete Mathematics for CS

Spring 2007 Luca Trevisan Lecture 19

Random Variables and Expectation

Question : The homeworks of 20 students are collected in, randomly shuffled and returned to the students. How many students receive their own homework? To answer this question, we first need to specify the probability space: plainly, it should consist of all 20! permutations of the homeworks, each with probability (^) 20!^1. [Note that this is the same as the probability space for card shuffling, except that the number of items being shuffled is now 20 rather than 52.] It helps to have a picture of a permutation. Think of 20 books lined up on a shelf, labeled from left to right with 1 , 2 ,... , 20. A permutation π is just a reordering of the books, which we can describe just by listing their labels from left to right. Let’s denote by π i the label of the book that is in position i. We are interested in the number of books that are still in their original position, i.e., in the number of i ’s such that π i = i. These are often known as fixed points of the permutation. Of course, our question does not have a simple numerical answer (such as 6), because the number depends on the particular permutation we choose (i.e., on the sample point). Let’s call the number of fixed points X. To make life simpler, let’s also shrink the class size down to 3 for a while. The following table gives a complete listing of the sample space (of size 3! = 6), together with the corresponding value of X for each sample point. [We use our bookshelf convention for writing a permutation: thus, for example, the permutation 312 means that book 3 is on the left, book 1 in the center, and book 2 on the right. You should check you agree with this table.] permutation π value of X 123 3 132 1 213 1 231 0 312 0 321 1 Thus we see that X takes on values 0, 1 or 3, depending on the sample point. A quantity like this, which takes on some numerical value at each sample point, is called a random variable (or r.v. ) on the sample space. Definition 19.1 (random variable) : A random variable X on a sample space Ω is a function that assigns to each sample point ω ∈ Ω a real number X ( ω). Until further notice, we’ll restrict out attention to discrete random variables: i.e., their values will be integers or rationals, rather than arbitrary real numbers. The r.v. X in our permutation example above is completely specified by its values at all sample points, as

given in the above table. (Thus, for example, X ( 123 ) = 3 etc.) Rather than the value at each sample point, we are usually more interested in the set of points at which the r.v. takes on some given value. Let a be any real number. Then the set { ω ∈ Ω : X ( ω) = a } is an event in the sample space (why?). We usually abbreviate this event to simply “ X = a ”. Since X = a is an event, we can talk about its probability, Pr[ X = a ]. The collection of these probabilities, for all possible values of a , is known as the distribution of the r.v. X. Definition 19.2 (distribution) : The distribution of a discrete random variable X is the collection of values {( a , Pr[ X = a ]) : a ∈ A }, where A is the set of all possible values taken by X. [In most of our examples, A will be (some subset of) the integers.] Thus the distribution of the random variable X in our permutation example above is Pr[ X = 0 ] =

; Pr[ X = 1 ] =

; Pr[ X = 3 ] =

and Pr[ X = a ] = 0 for all other values of a. Notice that the sum of the probabilities Pr[ X = a ] over all possible values of a is exactly 1. This must always be the case, for any random variable. Why? Because any random variable X must take on one, and only one, value X ( ω) at every sample point ω. I.e., the events X = a partition the sample space. So when we sum up the probabilities of the events X = a , we are really summing up the probabilities of all the sample points.

Expectation

In most applications, the complete distribution of a r.v. is very hard to calculate: for example, suppose we go back to our original question with 20 students. In principle, we’d have to enumerate 20! ≈ 2. 4 × 1018 sample points, compute the value of X at each one, and count the number of points at which X takes on each of its possible values! Moreover, even when we can compute the complete distribution of a r.v., it is often not very informative. For these reasons, we seek to compress the distribution into a more compact, convenient form that is also easier to compute. The most widely used such form is the expectation (or mean or average ) of the r.v. Definition 19.3 (expectation) : The expectation of a discrete random variable X is defined as E( X ) = (^) ∑ a ∈A a × Pr[ X = a ], where the sum is over all possible values taken by the r.v. For our running permutation example, the expectation is E( X ) =

0 ×

1 ×

3 ×

I.e., the expected number of fixed points in a permutation of three items is exactly 1.

Proof : To make the proof easier, we will first rewrite the definition of expectation in a more convenient form. Recall from Definition 20.3 that E( X ) = (^) ∑ a ∈A a × Pr[ X = a ]. Let’s look at one term a × Pr[ X = a ] in the above sum. Notice that Pr[ X = a ], by definition, is the sum of Pr[ ω] over those sample points ω for which X ( ω) = a. And we know that every sample point ω ∈ Ω is in exactly one of these events X = a. This means we can write out the above definition in a more long-winded form as E( X ) = (^) ∑ ω∈ Ω X ( ω) × Pr[ ω]. (1) This equivalent definition of expectation will make the present proof much easier (though it is usually less convenient for actual calculations). Now let’s write out E( X + Y ) using equation (1). E( X + Y ) = (^) ∑ ω∈ Ω ( X + Y )( ω) × Pr[ ω] = (^) ∑ ω∈ Ω ( X ( ω) + Y ( ω)) × Pr[ ω] = (^) ∑ ω∈ Ω

X ( ω) × Pr[ ω]

  • (^) ∑ ω∈ Ω

Y ( ω) × Pr[ ω]

= E( X ) + E( Y ).

In the last step, we used equation (1) twice. This completes the proof of the first equality. The proof of the second equality is much simpler and is left as an exercise.! Theorem 20.1 is very powerful: it says that the expectation of a sum of r.v.’s is the sum of their expectations, with no assumptions about the r.v.’s. (Note that we didn’t require, for example, that X and Y are indepen- dent.) We can use Theorem 20.1 to conclude things like E( 3 X − 5 Y ) = 3E( X ) − 5E( Y ). This property is known as linearity of expectation. Important caveat: Theorem 20.1 does not say that E( XY ) = E( X )E( Y ) , or that E( (^1) X ) = (^) E(^1 X ) etc. These claims are not true in general. It is only sums and differences and constant multiples of random variables that behave so nicely. Now let’s see some examples of Theorem 20.1 in action.

  1. Two dice again. Here’s a much less painful way of computing E( X ), where X is the sum of the scores of the two dice. Note that X = X 1 + X 2 , where Xi is the score on die i. We know from example 1 above that E( X 1 ) = E( X 2 ) = 72. So by Theorem 20.1 we have E( X ) = E( X 1 ) + E( X 2 ) = 7.
  2. More roulette. Suppose we play the above roulette game not once, but 1000 times. Let X be our expected net winnings. Then X = X 1 + X 2 +... + X 1000 , where Xi is our net winnings in the i th play. We know from earlier that E( Xi ) = − 191 for each i. Therefore, by Theorem 20.1, E( X ) = E( X 1 ) + E( X 2 ) + · · · + E( X 1000 ) = 1000 × (− 191 ) = − 100019 ≈ 53. So if you play 1000 games, you expect to lose about $53.
  3. Homeworks. Let’s go back and answer our original question about the class of 20 students. Recall that the r.v. X is the number of students who receive their own homework after shuffling (or equiva- lently, the number of fixed points). To take advantage of Theorem 20.1, we need to write X as the sum

of simpler r.v.’s. But since X counts the number of times something happens, we can write it as a sum using the following trick: X = X 1 + X 2 +... + X 20 , where Xi =

1 i f student i gets her own hw ; 0 otherwise

[You should think about this equation for a moment. Remember that all the X ’s are random variables. What does an equation involving random variables mean? What we mean is that, at every sample point ω, we have X ( ω) = X 1 ( ω) + X 2 ( ω) +... + X 20 ( ω). Why is this true?] A 0/1-valued random variable such as Xi is called an indicator random variable of the corresponding event (in this case, the event that student i gets her own hw). For indicator r.v.’s, the expectation is particularly easy to calculate. Namely, E( Xi ) = ( 0 × Pr[ Xi = 0 ]) + ( 1 × Pr[ Xi = 1 ]) = Pr[ Xi = 1 ]. But in our case, we have Pr[ Xi = 1 ] = Pr[student i gets her own hw] =

Now we can apply Theorem 20.1 to (2), to get E( X ) = E( X 1 ) + E( X 2 ) + · · · + E( X 20 ) = 20 ×

So we see that the expected number of students who get their own homeworks in a class of size 20 is 1. But this is exactly the same answer as we got for a class of size 3! And indeed, we can easily see from the above calculation that we would get E( X ) = 1 for any class size n : this is because we can write X = X 1 + X 2 +... + Xn , and E( Xi ) = (^1) n for each i. So the expected number of fixed points in a random permutation of n items is always 1 , regardless of n. Amazing, but true.

  1. Coin tosses. Toss a fair coin 100 times. Let the r.v. X be the number of Heads. As in the previous example, to take advantage of Theorem 20.1 we write X = X 1 + X 2 +... + X 100 , where Xi is the indicator r.v. of the event that the i th toss is Heads. Since the coin is fair, we have E( Xi ) = Pr[ Xi = 1 ] = Pr[ i th toss is Heads] = 12. Using Theorem 20.1, we therefore get E( X ) = 100 ∑ i = 1

= 100 × 12 = 50.

More generally, the expected number of Heads in n tosses of a fair coin is n 2. And in n tosses of a biased coin with Heads probability p , it is np (why?).