• Home
  • Textbooks
  • Probability and Computing
  • Discrete Random Variables and Expectation

Probability and Computing

Michael Mitzenmacher , Eli Upfal

Chapter 2

Discrete Random Variables and Expectation - all with Video Answers

Educators


Chapter Questions

02:06

Problem 1

Suppose we roll a fair $k$-sided die with the numbers 1 through $k$ on the die's faces. If $X$ is the number that appears, what is $\mathbf{E}[X]$ ?

Lucas Finney
Lucas Finney
Numerade Educator
01:55

Problem 2

A monkey types on a 26-letter keyboard that has lowercase letters only. Each letter is chosen independently and uniformly at random from the alphabet. If the monkey types $1,000,000$ letters, what is the expected number of times the sequence "proof" appears?

Hailey Tomashek
Hailey Tomashek
Numerade Educator
02:12

Problem 3

Give examples of functions $f$ and random variables $X$ where $\mathbf{E}[f(X)] \leq$ $f(\mathbf{E}[X]), \mathbf{E}[f(X)]=f(\mathbf{E}[X])$, and $\mathbf{E}[f(X)] \geq f(\mathbf{E}[X])$

Kayla Robinson
Kayla Robinson
Numerade Educator
01:58

Problem 4

Prove that $\mathbf{E}\left[X^{k}\right] \geq \mathbf{E}[X]^{k}$ for any even integer $k \geq 1$

Julian Wong
Julian Wong
Numerade Educator
02:52

Problem 5

If $X$ is a $B(n, 1 / 2)$ random variable with $n \geq 1$, show that the probability that $X$ is even is $1 / 2$.

Hunza Gilgit
Hunza Gilgit
Numerade Educator
05:45

Problem 6

Suppose that we independently roll two standard six-sided dice. Let $X_{1}$ be the number that shows on the first die, $X_{2}$ the number on the second die, and $X$ the sum of the numbers on the two dice.
(a) What is $\mathbf{E}\left[X \mid X_{1}\right.$ is even $] ?$
(b) What is $\mathbf{E}\left[X \mid X_{1}=X_{2}\right] ?$
(c) What is $\mathbf{E}\left[X_{1} \mid X=9\right]$ ?
(d) What is $\mathbf{E}\left[X_{1}-X_{2} \mid X=k\right]$ for $k$ in the range $[2,12] ?$

Bryan Lynn
Bryan Lynn
Numerade Educator
02:59

Problem 7

Let $X$ and $Y$ be independent geometric random variables, where $X$ has parameter $p$ and $Y$ has parameter $q$.
(a) What is the probability that $X=Y ?$
(b) What is $\mathbf{E}[\max (X, Y)]$ ?
(c) What is $\operatorname{Pr}(\min (X, Y)=k)$ ?
(d) What is $\mathbf{E}[X \mid X \leq Y]$ ?
You may find it helpful to keep in mind the memoryless property of geometric random variables.

Wei Zhang
Wei Zhang
Numerade Educator
03:34

Problem 8

(a) Alice and Bob decide to have children until either they have their first girl or they have $k \geq 1$ children. Assume that each child is a boy or girl independently with probability $1 / 2$ and that there are no multiple births. What is the expected number of female children that they have? What is the expected number of male children that they have?
(b) Suppose Alice and Bob simply decide to keep having children until they have their first girl. Assuming that this is possible, what is the expected number of boys that they have?

Sheryl Ezze
Sheryl Ezze
Numerade Educator
05:55

Problem 9

(a) Suppose that we roll twice a fair $k$-sided die with the numbers 1 through $k$ on the die's faces, obtaining values $X_{1}$ and $X_{2}$. What is $\mathbf{E}\left[\max \left(X_{1}, X_{2}\right)\right]$ ? What is $\mathbf{E}\left[\min \left(X_{1}, X_{2}\right)\right]$ ?
(b) Show from your calculations in part (a) that
$$
\mathbf{E}\left[\max \left(X_{1}, X_{2}\right)\right]+\mathbf{E}\left[\min \left(X_{1}, X_{2}\right)\right]=\mathbf{E}\left[X_{1}\right]+\mathbf{E}\left[X_{2}\right] .
$$
(c) Explain why Eqn. (2.1) must be true by using the linearity of expectations instead of a direct computation.

Muhammad Nawaz
Muhammad Nawaz
Numerade Educator
01:14

Problem 10

(a) Show by induction that if $f: \mathbf{R} \rightarrow \mathbf{R}$ is convex then, for any $x_{1}, x_{2}, \ldots, x_{n}$ and $\lambda_{1}, \lambda_{2}, \ldots, \lambda_{n}$ with $\sum_{i=1}^{n} \lambda_{i}=1$,
$$
f\left(\sum_{i=1}^{n} \lambda_{i} x_{i}\right) \leq \sum_{i=1}^{n} \lambda_{i} f\left(x_{i}\right)
$$
(b) Use Eqn. (2.2) to prove that if $f: \mathbf{R} \rightarrow \mathbf{R}$ is convex then
$$
\mathbf{E}[f(X)] \geq f(\mathbf{E}[X])
$$
for any random variable $X$ that takes on only finitely many values.

Stark Ledbetter
Stark Ledbetter
Numerade Educator
03:19

Problem 11

Prove Lemma $2.6 .$

Ernest Castorena
Ernest Castorena
Numerade Educator
03:38

Problem 12

We draw cards uniformly at random with replacement from a deck of $n$ cards. What is the expected number of cards we must draw until we have seen all $n$ cards in the deck? If we draw $2 n$ cards, what is the expected number of cards in the deck that are not chosen at all? Chosen exactly once?

Christopher Stanley
Christopher Stanley
Numerade Educator
07:48

Problem 13

(a) Consider the following variation of the coupon collector's problem. Each box of cereal contains one of $2 n$ different coupons. The coupons are organized into $n$ pairs, so that coupons 1 and 2 are a pair, coupons 3 and 4 are a pair, and so on. Once you obtain one coupon from every pair, you can obtain a prize. Assuming that the coupon in each box is chosen independently and uniformly at random from the $2 n$ possibilities, what is the expected number of boxes you must buy before you can claim the prize?
(b) Generalize the result of the problem in part (a) for the case where there are $k n$ different coupons, organized into $n$ disjoint sets of $k$ coupons, so that you need one coupon from every set.

Robin Corrigan
Robin Corrigan
Numerade Educator
02:44

Problem 14

The geometric distribution arises as the distribution of the number of times we flip a coin until it comes up heads. Consider now the distribution of the number of flips $X$ until the $k$ th head appears, where each coin flip comes up heads independently with probability $p$. Prove that this distribution is given by
$$
\operatorname{Pr}(X=n)=\left(\begin{array}{l}
n-1 \\
k-1
\end{array}\right) p^{k}(1-p)^{n-k}
$$
for $n \geq k$. (This is known as the negative binomial distribution.)

Sheryl Ezze
Sheryl Ezze
Numerade Educator
15:03

Problem 15

For a coin that comes up heads independently with probability $p$ on each flip, what is the expected number of flips until the $k$ th heads?

Mengchun Cai
Mengchun Cai
Numerade Educator
07:45

Problem 16

Suppose we flip a coin $n$ times to obtain a sequence of flips $X_{1}, X_{2}, \ldots$, $X_{n+}$ A streak of flips is a consecutive subsequence of flips that are all the same. For example, if $X_{3}, X_{4}$, and $X_{5}$ are all heads, there is a streak of length 3 starting at the third flip. (If $X_{6}$ is also heads, then there is also a streak of length 4 starting at the third flip.)
(a) Let $n$ be a power of $2 .$ Show that the expected number of streaks of length $\log _{2} n+1$ is $1-o(1)$.
(b) Show that, for sufficiently large $n$, the probability that there is no streak of length at least $\left[\log _{2} n-2 \log _{2} \log _{2} n\right\rfloor$ is less than $1 / n$. (Hint: Break the sequence of flips up into disjoint blocks of $\left\lfloor\log _{2} n-2 \log _{2} \log _{2} n\right\rfloor$ consecutive flips, and use that the event that one block is a streak is independent of the event that any other block is a streak.)

Mengchun Cai
Mengchun Cai
Numerade Educator
03:11

Problem 17

Recall the recursive spawning process described in Section 2.3. Suppose that each call to process $\mathcal{S}$ recursively spawns new copies of the process $\mathcal{S}$, where the number of new copies is 2 with probability $p$ and 0 with probability $1-p$. If $Y_{i}$ denotes the number of copies of $\mathcal{S}$ in the $i$ th generation, determine $\mathbf{E}\left[Y_{i}\right]$. For what values of $p$ is the expected total number of copies bounded?

AH
Aimal Hassan
Numerade Educator
01:41

Problem 18

The following approach is often called reservoir sampling. Suppose we have a sequence of items passing by one at a time. We want to maintain a sample of one item with the property that it is uniformly distributed over all the items that we

Bryan Meares
Bryan Meares
Numerade Educator
01:33

Problem 19

Suppose that we modify the reservoir sampling algorithm of Exercise $2.18$ so that, when the $k$ th item appears, it replaces the item in memory with probability $1 / 2$. Describe the distribution of the item in memory.

Hunza Gilgit
Hunza Gilgit
Numerade Educator
06:44

Problem 20

A permutation on the numbers $[1, n]$ can be represented as a function $\pi:[1, n] \rightarrow[1, n]$, where $\pi(i)$ is the position of $i$ in the ordering given by the permutation. A fixed point of a permutation $\pi:[1, n] \rightarrow[1, n]$ is a value for which $\pi(x)=x$. Find the expected number of fixed points of a permutation chosen uniformly at random from all permutations.

Bryan Lynn
Bryan Lynn
Numerade Educator
01:15

Problem 21

Let $a_{1}, a_{2}, \ldots, a_{n}$ be a random permutation of $\{1,2, \ldots, n\}$, equally likely to be any of the $n !$ possible permutations. When sorting the list $a_{1}, a_{2}, \ldots, a_{n}$, the element $a_{i}$ must move a distance of $\left|a_{i}-i\right|$ places from its current position to reach its position in the sorted order. Find
$$
\mathbf{E}\left[\sum_{t=1}^{n}\left|a_{t}-i\right|\right]
$$
the expected total distance that elements will have to be moved.

Nick Johnson
Nick Johnson
Numerade Educator
01:15

Problem 22

Let $a_{1}, a_{2}, \ldots, a_{n}$ be a list of $n$ distinct numbers. We say that $a_{i}$ and $a_{j}$ are inverted if $i<j$ but $a_{i}>a_{j}$. The Bubblesort sorting algorithm swaps pairwise adjacent inverted numbers in the list until there are no more inversions, so the list is in sorted order. Suppose that the input to Bubblesort is a random permutation, equally likely to be any of the $n !$ permutations of $n$ distinct numbers. Determine the expected number of inversions that need to be corrected by Bubblesort.

Nick Johnson
Nick Johnson
Numerade Educator
10:41

Problem 23

Linear insertion sort can sort an array of numbers in place. The first and second numbers are compared; if they are out of order, they are swapped so that they are in sorted order. The third number is then placed in the appropriate place in the sorted order. It is first compared with the second; if it is not in the proper order, it is swapped and compared with the first. Iteratively, the $k$ th number is handled by swapping it downward until the first $k$ numbers are in sorted order. Determine the expected number of swaps that need to be made with a linear insertion sort when the input is a random permutation of $n$ distinct numbers.

Tarandeep Singh
Tarandeep Singh
Numerade Educator
07:54

Problem 24

We roll a standard fair die over and over. What is the expected number of rolls until the first pair of consecutive sixes appears?

Bryan Lynn
Bryan Lynn
Numerade Educator
00:42

Problem 25

A blood test is being performed on $n$ individuals. Each person can be tested separately, but this is expensive. Pooling can decrease the cost. The blood samples of $k$ people can be pooled and analyzed together. If the test is negative, this one test suffices for the group of $k$ individuals. If the test is positive, then each of the $k$ persons must be tested separately and thus $k+1$ total tests are required for the $k$ people.
Suppose that we create $n / k$ disjoint groups of $k$ people (where $k$ divides $n$ ) and use the pooling method. Assume that each person has a positive result on the test independently with probability $p$.
(a) What is the probability that the test for a pooled sample of $k$ people will be positive?
(b) What is the expected number of tests necessary?
(c) Describe how to find the best value of $k$.
(d) Give an inequality that shows for what values of $p$ pooling is better than just testing every individual.

Victor Salazar
Victor Salazar
Numerade Educator
00:47

Problem 26

A permutation $\pi:[1, n] \rightarrow[1, n]$ can be represented as a set of cycles as follows. Let there be one vertex for each number $i, i=1, \ldots, n$. If the permutation maps the number $i$ to the number $\pi(i)$, then a directed arc is drawn from vertex $i$ to vertex $\pi(i)$. This leads to a graph that is a set of disjoint cycles. Notice that some of the cycles could be self-loops. What is the expected number of cycles in a random permutation of $n$ numbers?

Clarissa Noh
Clarissa Noh
Numerade Educator
01:30

Problem 27

Consider the following distribution on the integers $x \geq 1: \operatorname{Pr}(X=x)=$ $\left(6 / \pi^{2}\right) x^{-2}$. This is a valid distribution, since $\sum_{k=1}^{\infty} k^{-2}=\pi^{2} / 6$. What is its expectation?

Gregory Higby
Gregory Higby
Numerade Educator
03:29

Problem 28

Consider a simplified version of roulette in which you wager $x$ dollars on either red or black. The wheel is spun, and you receive your original wager plus another $x$ dollars if the ball lands on your color; if the ball doesn't land on your color, you lose your wager. Each color occurs independently with probability $1 / 2$. (This is a simplification because real roulette wheels have one or two spaces that are neither red nor black, so the probability of guessing the correct color is actually less than $1 / 2 .)$
The following gambling strategy is a popular one. On the first spin, bet 1 dollar. If you lose, bet 2 dollars on the next spin. In general, if you have lost on the first $k-1$ spins, bet $2^{k-1}$ dollars on the $k$ th spin. Argue that by following this strategy you will eventually win a dollar. Now let $X$ be the random variable that measures your maximum loss before winning (i.e., the amount of money you have lost before the play on which you win). Show that $\mathbf{E}[X]$ is unbounded. What does it imply about the practicality of this strategy?

A M
A M
Numerade Educator
03:39

Problem 29

Prove that, if $X_{0}, X_{1}, \ldots$ is a sequence of random variables such that
$$
\sum_{j=0}^{\infty} \mathbf{E}\left[\left|\boldsymbol{X}_{j}\right|\right]
$$
converges, then the linearity of expectations holds:
$$
\mathbf{E}\left[\sum_{j=0}^{\infty} X_{j}\right]=\sum_{j=0}^{\infty} \mathbf{E}\left[X_{j}\right]
$$

Michelle Z.
Michelle Z.
Numerade Educator
00:59

Problem 30

In the roulette problem of Exercise 2.28, we found that with probability 1 you eventually win a dollar. Let $X_{j}$ be the amount you win on the $j$ th bet. (This might be 0 if you have already won a previous bet.) Determine $\mathbf{E}\left[X_{j}\right]$ and show that, by applying the linearity of expectations, you find your expected winnings are 0 . Does the linearity of expectations hold in this case?

Christopher Stanley
Christopher Stanley
Numerade Educator
01:33

Problem 31

A variation on the roulette problem of Exercise $2.28$ is the following. We repeatedly flip a fair coin. You pay $j$ dollars to play the game. If the first head comes up on the $k$ th flip, you win $2^{k} / k$ dollars. What are your expected winnings? How much would you be willing to pay to play the game?

Lauren Shelton
Lauren Shelton
Numerade Educator
08:25

Problem 32

You need a new staff assistant, and you have $n$ people to interview. You want to hire the best candidate for the position. When you interview a candidate, you can give them a score, with the highest score being the best and no ties being possible. You interview the candidates one by one. Because of your company's hiring practices, after you interview the $k$ th candidate, you either offer the candidate the job before the next interview or you forever lose the chance to hire that candidate. We suppose the candidates are interviewed in a random order, chosen uniformly at random from all $n$ ? possible orderings.

We consider the following strategy. First, interview $m$ candidates but reject them all; these candidates give you an idea of how strong the field is. After the $m$ th candidate, hire the first candidate you interview who is better than all of the previous candidates you have interviewed.
(a) Let $E$ be the event that we hire the best assistant, and let $E_{i}$ be the event that $i$ th candidate is the best and we hire him. Determine $\operatorname{Pr}\left(E_{i}\right)$, and show that
$$
\operatorname{Pr}(E)=\frac{m}{n} \sum_{j=m+1}^{n} \frac{1}{j-1}
$$
(b) Bound $\sum_{j=m+1}^{n} \frac{1}{j-1}$ to obtain
$$
\frac{m}{n}(\ln n-\ln m) \leq \operatorname{Pr}(E) \leq \frac{m}{n}(\ln (n-1)-\ln (m-1)) .
$$
(c) Show that $m(\ln n-\ln m) / n$ is maximized when $m=n / e$, and explain why this means $\operatorname{Pr}(E) \geq 1 / \mathrm{e}$ for this choice of $m$.

Robin Corrigan
Robin Corrigan
Numerade Educator