• Home
  • Textbooks
  • Probability and Computing
  • The Monte Carlo Method

Probability and Computing

Michael Mitzenmacher , Eli Upfal

Chapter 10

The Monte Carlo Method - all with Video Answers

Educators


Chapter Questions

02:48

Problem 1

Formally prove Theorem 10.1.

Nick Johnson
Nick Johnson
Numerade Educator
00:57

Problem 2

Another method for approximating $\pi$ using Monte Carlo techniques is based on Buffon's needle experiment. Research and explain Buffon's needle experiment, and further explain how it can be used to obtain an approximation for $\pi$.

Amany Waheeb
Amany Waheeb
Numerade Educator
01:34

Problem 3

Show that the following alternative definition is equivalent to the definition of an FPRAS given in the chapter: A fully polynomial randomized approximation scheme (FPRAS) for a problem is a randomized algorithm for which, given an input $x$ and any parameter $\varepsilon$ with $0<\varepsilon<1$, the algorithm outputs an $(\varepsilon, 1 / 4)$-approximation in time that is polynomial in $1 / \varepsilon$ and the size of the input $x$. (Hint: To boost the probability of success from $3 / 4$ to $1-\delta$, consider the median of several independent runs of the algorithm. Why is the median a better choice than the mean?)

Anurag Kumar
Anurag Kumar
Numerade Educator
01:53

Problem 4

Suppose we have a class of instances of the DNF satisfiability problem, each with $\alpha(n)$ satisfying truth assignments for some polynomial $\alpha$. Suppose we apply the naïve approach of sampling assignments and checking whether they satisfy the formula. Show that, after sampling $2^{n / 2}$ assignments, the probability of finding even a single satisfying assignment for a given instance is exponentially small in $n$.

Hast Aggarwal
Hast Aggarwal
Numerade Educator
View

Problem 5

(a) Let $S_{1}, S_{2}, \ldots, S_{m}$ be subsets of a finite universe $U .$ We know $\left|S_{i}\right|$ for $1 \leq i \leq m$. We wish to obtain an $(\varepsilon, \delta)$-approximation to the size of the set
$$
S=\bigcup_{i=1}^{m} S_{i}
$$
We have available a procedure that can, in one step, choose an element uniformly at random from a set $S_{i}$. Also, given an element $x \in U$, we can determine the number of sets $S_{i}$ for which $x \in S_{i}$. We call this number $c(x)$.
Define $p_{i}$ to be
$$
p_{i}=\frac{\left|S_{i}\right|}{\sum_{j=1}^{m}\left|S_{j}\right|}
$$
The $j$ th trial consists of the following steps. We choose a set $S_{j}$, where the probability of each set $S_{i}$ being chosen is $p_{i}$, and then we choose an element $x_{j}$ uniformly at random from $S_{j} .$ In each trial the random choices are independent of all other trials. After $t$ trials, we estimate $|S|$ by
$$
\left(\frac{1}{t} \sum_{j=1}^{t} \frac{1}{c\left(x_{j}\right)}\right)\left(\sum_{i=1}^{m}\left|S_{i}\right|\right)
$$
Determine - as a function of $m, \varepsilon$, and $\delta$ - the number of trials needed to obtain an $(\varepsilon, \delta)$-approximation to $|S|$.
(b) Explain how to use your results from part (a) to obtain an alternative approximation algorithm for counting the number of solutions to a DNF formula.

Victor Salazar
Victor Salazar
Numerade Educator
04:51

Problem 6

The problem of counting the number of solutions to a knapsack instance can be defined as follows: Given items with sizes $a_{1}, a_{2}, \ldots, a_{n}>0$ and an integer $b>$ 0 , find the number of vectors $\left(x_{1}, x_{2}, \ldots, x_{n}\right) \in\{0,1\}^{n}$ such that $\sum_{i=1}^{n} a_{i} x_{i} \leq b$. The number $b$ can be thought of as the size of a knapsack, and the $x_{1}$ denote whether or not each item is put into the knapsack. Counting solutions corresponds to counting the number of different sets of items that can be placed in the knapsack without exceeding its capacity.
(a) A naïve way of counting the number of solutions to this problem is to repeatedly choose $\left(x_{1}, x_{2}, \ldots, x_{n}\right) \in\{0,1\}^{n}$ uniformly at random, and return the $2^{n}$ times the fraction of samples that yield valid solutions. Argue why this is not a good strategy in general; in particular, argue that it will work poorly when each $a_{i}$ is 1 and $b=\sqrt{n}$.
(b) Consider a Markov chain $X_{0}, X_{1}, \ldots$ on vectors $\left(x_{1}, x_{2}, \ldots, x_{n}\right) \in\{0,1\}^{n} .$ Suppose $X_{j}$ is $\left(x_{1}, x_{2}, \ldots, x_{n}\right)$. At each step, the Markov chain chooses $i \in[1, n]$ uniformly at random. If $x_{i}=1$, then $X_{j+1}$ is obtained from $X_{j}$ by setting $x_{i}$ to 0 . If $x_{i}=0$, then $X_{j+1}$ is obtained from $X_{j}$ by setting $x_{l}$ to 1 if doing so maintains the restriction $\sum_{i=1}^{n} a_{i} x_{i} \leq b .$ Otherwise, $X_{j+1}=X_{j} .$

Argue that this Markov chain has a uniform stationary distribution whenever $\sum_{i=1}^{n} a_{i}>b$. Be sure to argue that the chain is irreducible and aperiodic.
(c) Argue that, if we have an FPAUS for the knapsack problem, then we can derive an FPRAS for the problem. To set the problem up properly, assume without loss of generality that $a_{1} \leq a_{2} \leq \cdots \leq a_{n}$. Let $b_{0}=0$ and $b_{1}=\sum_{j=1}^{l} a_{i}$. Let $\Omega\left(b_{i}\right)$ be the set of vectors $\left(x_{1}, x_{2}, \ldots, x_{n}\right) \in\{0,1\}^{n}$ that satisfy $\sum_{i=1}^{n} a_{t} x_{i} \leq b_{1}$. Let $k$ be the smallest integer such that $b_{k} \geq b$. Consider the equation
$$
|\Omega(b)|=\frac{|\Omega(b)|}{\left|\Omega\left(b_{k-1}\right)\right|} \times \frac{\left|\Omega\left(b_{k-1}\right)\right|}{\left|\Omega\left(b_{k-2}\right)\right|} \times \cdots \times \frac{\left|\Omega\left(b_{1}\right)\right|}{\left|\Omega\left(b_{0}\right)\right|} \times\left|\Omega\left(b_{0}\right)\right|
$$
You will need to argue that $\left|\Omega\left(b_{i-1}\right)\right| /\left|\Omega\left(b_{i}\right)\right|$ is not too small. Specifically, argue that $\left|\Omega\left(b_{i}\right)\right| \leq(n+1)\left|\Omega\left(b_{i-1}\right)\right|$.

Hunza Gilgit
Hunza Gilgit
Numerade Educator
05:03

Problem 7

An alternative definition for an $\varepsilon$-uniform sample of $\Omega$ is as follows: A sampling algorithm generates an $\varepsilon$-uniform sample $w$ if, for all $x \in \Omega$,
$$
\frac{|\operatorname{Pr}(w=x)-1 /| \Omega||}{1 /|\Omega|} \leq \varepsilon
$$
Show that an $\varepsilon$-uniform sample under this definition yields an $\varepsilon$-uniform sample as given in Definition $10.3$

James Kiss
James Kiss
Numerade Educator
07:01

Problem 8

Let $S=\sum_{i=1}^{\infty} i^{-2}=\pi^{2} / 6$. Design a Markov chain based on the Metropolis algorithm on the positive integers such that, in the stationary distribution, $\pi_{t}=$ $1 / S i^{2}$. The neighbors of any integer $i>1$ for your chain should be only $i-1$ and $i+1$; and the only neighbor of 1 should be the integer 2 .

Robin Corrigan
Robin Corrigan
Numerade Educator
03:42

Problem 9

Recall the Bubblesort algorithm of Exercise 2.22. Suppose we have $n$ cards labeled 1 through $n$. The order of the cards $X$ can be the state of a Markov chain. Let $f(X)$ be the number of Bubblesort moves necessary to put the cards in increasing sorted order. Design a Markov chain based on the Metropolis algorithm such that, in the stationary distribution, the probability of an order $X$ is proportional to $\lambda^{f(X)}$ for a given constant $\lambda>0$. Pairs of states of the chain are connected if they correspond to pairs of orderings that can be obtained by interchanging at most two cards.

Amany Waheeb
Amany Waheeb
Numerade Educator
02:31

Problem 10

A $\Delta$-coloring $C$ of an undirected graph $G=(V, E)$ is an assignment labeling each vertex with a number, representing a color, from the set $\{1,2, \ldots, \Delta\} .$ An edge $(u, v)$ is improper if both $u$ and $v$ are assigned the same color. Let $I(C)$ be the number of improper edges of a coloring $C$. Design a Markov chain based on the Metropolis algorithm such that, in the stationary distribution, the probability of a coloring $C$ is proportional to $\lambda^{I(C)}$ for a given constant $\lambda>0$. Pairs of states of the chain are connected if they correspond to pairs of colorings that differ in just one vertex.

Nick Johnson
Nick Johnson
Numerade Educator
07:01

Problem 11

In Section 10.4.1 we constructed a Markov chain on the independent sets of a graph where, in the stationary distribution, $\pi_{x}=\lambda^{\left|I_{x}\right|} / B .$ Here $I_{x}$ is the independent set corresponding to state $x$ and $B=\sum_{x} \lambda^{\lambda I_{x} t} .$ Using a similar approach, construct a Markov chain on the independent sets of a graph excluding the empty set, where $\pi_{x}=\left|I_{x}\right| / B$ for a constant $B$. Because the chain excludes the empty set, you should first design a neighborhood structure that ensures the state space is connected.

Robin Corrigan
Robin Corrigan
Numerade Educator
07:01

Problem 12

The following generalization of the Metropolis algorithm is due to Hastings. Suppose that we have a Markov chain on a state space $\Omega$ given by the transition matrix $\mathbf{Q}$ and that we want to construct a Markov chain on this state space with a stationary distribution $\pi_{x}=b(x) / B$, where for all $x \in \Omega, b(x)>0$ and $B=$ $\sum_{x \in \Omega} b(x)$ is finite. Define a new Markov chain as follows. When $X_{n}=x$, generate a random variable $Y$ with $\operatorname{Pr}(Y=y)=Q_{x, y} .$ Notice that $Y$ can be generated by simulating one step of the original Markov chain. Set $X_{n+1}$ to $Y$ with probability
$$
\min \left(\frac{\pi_{y} Q_{y_{,} x}}{\pi_{x} Q_{x, y}}, 1\right),
$$
and otherwise set $X_{n+1}$ to $X_{n} .$ Argue that, if this chain is aperiodic and irreducible, then it is also time reversible and has a stationary distribution given by the $\pi_{x}$.

Robin Corrigan
Robin Corrigan
Numerade Educator
View

Problem 13

Suppose we have a program that takes as input a number $x$ on the real interval $[0,1]$ and outputs $f(x)$ for some bounded function $f$ taking on values in the range $[1, b]$. We want to estimate
$$
\int_{x=0}^{1} f(x) d x
$$
Assume that we have a random number generator that can generate independent uniform random variables $X_{1}, X_{2}, \ldots$. Show that $$
\sum_{i=1}^{m} \frac{f\left(X_{i}\right)}{m}
$$
gives an ( $\varepsilon, \delta$ )-approximation for the integral for a suitable value of $m$.

Rashmi Sinha
Rashmi Sinha
Numerade Educator