\documentclass[twocolumn]{article}
% \documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} (20)  This problem concerns the ALOHA network model.  Continue to
assume that $p = 0.4$, $q = 0.8$, $X_0 = 2$ and that the network
consists of just two nodes.  Suppose $X_1 = 2$.  Find the probability
that both nodes tried to send during epoch 1.

{\bf 2.}  This problem concerns the bus ridership example, pp.20ff.

\begin{itemize}

\item [(a)] (20) Supply the reason for Equation (2.54), in the form of a
``mailing tube'' number, e.g. (2.5).  (Write your answer in the form
``(2.x)'', NOT ``Equation (2.x)''.

\item [(b)] (20) In the second-to-last bullet, p.20, we state the
assumption that passengers make the decision to alight or not
independently.  In what equation, among (2.52)-(2.56), is that
assumption used?

\item [(c)] (20) An observer at the second stop notices that no one
alights there, but it is dark and the observer couldn't see whether
anyone was on the bus. Find the probability that there was one passenger
on the bus at the time.

\end{itemize}

{\bf 3.} (20) We toss a coin until we get $k$ heads in a row.  Let $N$
denote the number of tosses needed, so that for instance the pattern
HTHHH gives $N = 5$ for $k = 3$.  Fill in the blanks in the following
simulation code, which finds the approximate probability that $N > m$.

\begin{lstlisting}
ngtm <- function(k,m,nreps) {
   count <- 0
   for (rep in 1:nreps) {
      blank (a)
      for (i in 1: blank (b) ) {
         toss <- sample(0:1,1)
         if (toss) {
            consech <- consech + 1
            if (consech == blank (c) ) break
         } else consech <- 0
      }
      if (consech < k) count <- count + 1
   }
   return(count/ blank (d) )
}
\end{lstlisting}

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.}  $p^2 / (p^2+(1-p)^2)$

{\bf 2.a} (2.7)

{\bf 2.b} (2.55)

{\bf 2.c}  Let $A_i$ denote the number of passengers alighting at stop i.

\begin{eqnarray}
P(L_1 = 1 | A_2 = 0)
&=& \frac
{P(L_1 = 1 \textrm{ and } A_2 = 0)}
{P(A_2 = 0)} \\ 
&=& \frac
{P(L_1 = 1 \textrm{ and } A_2 = 0)}
{\sum_{j=0}^2
P(L_1 = j \textrm{ and } A_2 = 0)} \\
&=& 
\frac
{0.4 \cdot 0.8}
{0.5 \cdot 1 + 0.4 \cdot 0.8 + 0.1 \cdot 0.8^2}
\end{eqnarray}

{\bf 3.}

\begin{lstlisting}
ngtm <- function(k,m,nreps) {
   count <- 0
   for (rep in 1:nreps) {
      consech <- 0
      for (i in 1:m) {
         toss <- sample(0:1,1)
         if (toss) {
            consech <- consech + 1
            if (consech == k) break
         } else consech <- 0
      }
      if (consech < k) count <- count + 1
   }
   return(count/nreps)
}
\end{lstlisting}

\end{document}
