\documentclass[a4paper]{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{enumitem}

\graphicspath{ {./images/} }

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Question \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Question \arabic{homeworkProblemCounter}}{}\nobreak{}

\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Question \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

\newcommand{\hmwkClass}{INF 1004 Mathematics 2}
\newcommand{\hmwkTitle}{Tutorial\ \#3}
\newcommand{\hmwkAuthorName}{\textbf{Woon Jun Wei}}
\newcommand{\hmwkStudentID}{\textbf{2200624}}

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass \\ \hmwkTitle}}\\
    \vspace{3in}
}

\author{\hmwkAuthorName \\ \hmwkStudentID}
\date{\today}

\renewcommand{\part}[1]{\textbf{\large Part \arabic{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large My Solution\\}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\pagebreak

\begin{homeworkProblem}
A spam filter is designed by looking at commonly occurring phrases in spam. Suppose
that 80\% of email is spam. In 10\% of the spam emails, the phrase “free money” is used.
Whereas the phrase “free money” is used in only 1\% of non-spam emails. A new email
has just arrived, which does mention “free money”. What is the probability that it is
spam?
\\\\
    \solution
    $$
    \begin{aligned}
        P(\text{spam} \mid \text{free money}) &= \frac{P(\text{free money} \mid \text{spam}) \cdot P(\text{spam})}{P(\text{free money})} \\
        &= \frac{0.1 \cdot 0.8}{0.8 \cdot 0.1 + 0.2 \cdot 0.01} \\
        &= \frac{40}{41}\\
        &\approx 0.9756097561
    \end{aligned}
    $$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
A sample of people, who commute regularly from a town in
surrey into London, were asked for an estimate of the time
taken on their most recent journey. The replies are
summarized in the given table.
\\\\
\begin{tabular}{|c|c|}
\hline
Time in minutes & Frequency \\
\hline
35 to 45 & 12\\
45 to 55 & 54\\
55 to 65 & 68\\
65 to 85 & 41\\
85 to 105 & 23\\
\hline
\end{tabular}

    \begin{enumerate}[label=\alph*)]
        \item Calculate the estimate of the mean and the standard deviation of these times.
        \item What is the median?
        \item What is the mode?
    \end{enumerate}

    \solution
    \\
    \part \\

    Using the midpoints of the intervals, we can calculate the mean and standard deviation as follows:\\\\
\begin{tabular}{|c|c|c|c|}
\hline
Time in minutes & Frequency & $x_if_i$ & $(x_if_i)^2$\\
\hline
 40& 12 & 480 & 230400\\
 50& 54 & 2700 & 729000\\
 60& 68 & 4080 & 16646400\\
 70& 41 & 2870 & 8236900\\
 95& 23 & 2185 & 4774225\\
 \hline
 total & 198 & 12315 &  30616925\\
\hline
\end{tabular}
\\\\
$$
\begin{align}
    \bar{x} &= \frac{40 \cdot 12 + 50 \cdot 54 + 60 \cdot 68 + 70 \cdot 41 + 95 \cdot 23}{12 + 54 + 68 + 41 + 23} \\
    &= \frac{12735}{198} \\
    &= 62.19697 \text{ minutes}
    \\\\
    s &= \sqrt{\frac{1}{198 - 1} \sum x_i^2f_i-\frac{(\sum x_if_i)^2 }{n}}\\
      &= 14.517505\\
      &\approx 14.52
\end{align}
$$

\pagebreak

\part

The median is the middle value of the data set. Since there are 198 data points, the median is the average of the 99th and 100th data points.\\

Since the 99th and 100th data points lie in the 55 to 65 interval,

$$
\begin{align}
Q &=L_m +\Bigr( \frac{\frac{n}{2} -cf_{m-1}}{f_m}\Bigr)w_m\\
  &= 55 + \frac{\frac{198}{2} - 66}{68} \cdot 10\\
  &= 59.85294\\
  &\approx 59.85 \text{ minutes}
\end{align}
$$

\part

The modal class is the class "55 to 65" with a frequency of 68.

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
Maurice works at home. At 2 pm he decides to take a break to buy a copy of the chronicle
newspaper. There are three nearby newsagents: Arif, Bob and Carol. However, by 2 pm
they may have sold all their chronicles and so have none available. The independent
probabilities that they have a chronicle available at 2 pm are: Arif 0.4, Bob 0.7, Carol 0.25


    \begin{enumerate}[label=(\alph*)]
        \item Find the probability that none of the three newsagents have the chronicles at 2 pm.?
        \item Maurice decides to visit the newsagent in turn until he obtains a chronicle or until he has visited all three. He tosses a coin. If it lands heads he will visit the three newsagents in the order Bob, Arif, Carol. If it lands tail, he will visit them in order Carol, Arif, Bob. Find the probability that he will obtain a chronicle from Arif.
    \end{enumerate}

    \solution

    \part

    $$P(\text{none available}) = 0.6 \cdot 0.3 \cdot 0.75 = 0.045$$

    \part

    $$P(\text{Arif}) = 0.5\cdot 0.3 \cdot 0.4 \cdot 0.75 + 0.5 \cdot 0.75 \cdot 0.4 \cdot 0.0.3 = 0.09$$
    \\\\
    First statement: "Head", "bob", "arif", "carol"\\
    Second statement: "Tail", "carol", "arif", "bob"\\

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
     The following table summarizes the number of late arrivals of all students who attend a
certain school on 5 mornings of particular week. (Show your steps for all of the following.)
\\
\begin{tabular}{|c|c|}
\hline
Number of late arrivals & Number of Pupils\\
\hline
0 & 275\\
1 & 111\\
2 & 33\\
3 & 12\\
4 & 13\\
5 & 16\\
\hline
\end{tabular}
\\
    \begin{enumerate}[label=(\alph*)]
        \item Let random variable X=number of late arrivals. Is the random variable discrete or continuous?
        \item Draw the probability distribution for X. Calculate the mean and the standard deviation of the data in the table.
        \item Calculate the expected value.
    \end{enumerate}

    \solution

    \part

    The random variable is \boxed{discrete}.
\\\\
    \part

\\
\begin{tabular}{|c|c|c|c|}
\hline
Number of late arrivals & Number of Pupils &$P(X)$ & $P(X) \cdot x$\\
\hline
0 & 275 & $\frac{265}{460} \approx 0.598$ & 0\\
1 & 111 & $\frac{111}{460} \approx 0.241$ & 0.241\\
2 & 33 & $\frac{33}{460} \approx 0.072$ & 0.143\\
3 & 12 & $\frac{12}{460} \approx 0.026$ & 0.5217\\
4 & 13 & $\frac{13}{460} \approx 0.028$ & 0.0565\\
5 & 16 & $\frac{16}{460} \approx 0.035$ & 0.0695\\
\hline
\end{tabular}
\\\\
$$\text{mean} = \frac{275 \cdot 0 + 111 \cdot 1 + 33 \cdot 2 + 12 \cdot 3 + 13 \cdot 4 + 16 \cdot 5}{460} \approx 0.75$$

$$
\begin{align}
    s &= \sqrt{\frac{1}{460 - 1} \sum x_i^2p_i-\frac{(\sum x_ip_i)^2 }{n}}\\
    &= 1.23515
\end{align}
$$
\part

$$E(x) = 0.75$$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    A Terrence walks to school every morning. The probability that he arrives late is 0.15 and
independent of whether he arrives late on any other morning. For a week, in which he
decides to walk to school on five mornings, find:
    \begin{enumerate}[label=(\alph*)]
        \item Probability he arrives late on two or fewer mornings.
        \item Probability he arrives late on three or more mornings.
        \item Find the mean and standard deviation of the number of mornings on which he arrives late.?
    \end{enumerate}

\solution

Let X be the number of days he arrives late.\\
n = 5\\
p(X) = 0.15\\

\part

$$
\begin{align}
P(X \leq 2) &= P(X = 0) + P(X = 1) + P(X = 2)\\
              &= \binom{5}{2}(o.15)^2(1-0.15)^{5-2} + \binom{5}{1}(0.15)(1-0.15)^{5-1} + \binom{5}{0}(1-0.15)^5\\
    &= 0.973388125\\
    &\approx 0.9734
\end{align}

$$

\part

$$
\begin{align}
P(X \geq 3) &= P(X = 3) + P(X = 4) + P(X = 5)\\
            &= \binom{5}{3}(0.15)^3(1-0.15)^{5-3} + \binom{5}{4}(0.15)^4(1-0.15)^{5-4} + \binom{5}{5}(0.15)^5\\
    &= 0.026611875\\
    &\approx 0.0266
\end{align}
$$

\part

$$
\begin{align}
    E(x) &= 5 \cdot 0.15 = 0.75\\
    Var(X) &= 0.75(1-0.15) = 0.6375\\
    s &= \sqrt{0.6375} \approx 0.799
\end{align}



\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
 Bob is a student who travels to and from University by bus. He believes that the
probability of having to wait more than six minutes to catch a bus is 0.4 and is
independent of the time of day and direction of travel.
    \begin{enumerate}[label=(\alph*)]
        \item Assuming Bob beliefs are correct. Calculate values for the mean and standard deviation of the number of times he has to wait more than six minutes to catch a bus in a week when he catches 10 buses.
        \item During a thirteen-week period, the number of times (out of 10) he had to wait more than six minutes to catch a bus were as follows:
$$4, 8, 8, 9, 3, 2, 2, 7, 0, 1, 5, 2, 0$$
        \begin{enumerate}[label=(\roman*)]
            \item Calculate the mean and standard deviation of this data.
            \item Does the answer in (b)i support Bob’s beliefs that the probability of having to wait more than six minutes to catch a bus is constant as 0.4 regardless of any factors?
        \end{enumerate}
        \end{enumerate}

        \solution
        \\
        \textbf{Given}:\\
        n = 10\\
        p(X) = 0.4\\

        \part

        $$
        \begin{align}
            E(X) &= 10 \cdot 0.4 = 4\\
            Var(X) &= 10 \cdot 0.4 \cdot 0.6 = 2.4\\
            s &= \sqrt{2.4} \approx 1.549
        \end{align}
        $$

        \part

        $$
        \begin{align}
            E(X) &= \frac{4+8+8+9+3+2+2+7+0+1+5+2+0}{10} \approx 3.923076923\\
            s &= \sqrt{\frac{1}{10-1} \sum (x_i - 3.6923)^2} \approx 3.17441
        \end{align}
        $$

        \part

        The Mean of the data is 3.6923 which is not equal to 0.4. Therefore, Bob's belief is incorrect.

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
A shop sells two types of bath cubes: relaxing and invigorating. The owner of a hotel
buys 50 cubes from this shop. For each cube, there is independently a probability of 0.4
that it will be relaxing.
    \begin{enumerate}[label=(\alph*)]
        \item Find the probability that more than 90\% of the 50 cubes will be relaxing cubes.
        \item The 50 cubes included 22 relaxing cubes. Give a reason, whether or not a
binomial distribution will provide an appropriate model for the random variable,
R, in each of the following cases:
        \begin{enumerate}[label=(\roman*)]
            \item A guest at the hotel randomly selects one of the 50 cubes. If it is not a
relaxing cube, he replaces it and again selects a cube at random. He
continues this procedure until he obtains a relaxing cube. The random
variable R denotes the number of cubes he selects until he obtains a
relaxing cube.
            \item The owner randomly selects 20 of the 50 cubes and places them in a
bowl. The random variable R denotes the number of relaxing cubes
placed in the bowl; each being evaluated as one trial.
        \end{enumerate}
    \end{enumerate}

    \solution

    \part

    Let X= the number of relaxing cubes.\\
    \textbf{Given}:\\
    p(X) = 0.4\\

    90\% of 50 = 45\\

    $$
    \begin{align}
        p(X > 45) &=  p(X = 46) + p(X = 47) + p(X = 48) + p(X = 49) + p(X = 50)\\
        &= \binom{50}{46}(0.4)^{46}(0.6)^{50-46} + \binom{50}{47}(0.4)^{47}(0.6)^{50-47}\\
        &+ \binom{50}{48}(0.4)^{48}(0.6)^{50-48} + \binom{50}{49}(0.4)^{49}(0.6)^{50-49}\\
        &+ \binom{50}{50}(0.4)^{50}(0.6)^{50-50}\\
        &=
    \end{align}
    $$

    \part

    As p(R) is not an independent event, the binomial distribution will not be an appropriate model for the random variable R.
    The variable n is also not fixed, therefore, the binomial distribution will not be an appropriate model for the random variable R.

    \part

    As the probability is not constant, the binomial distribution will not be an appropriate model for the random variable R.



\end{homeworkProblem}


\end{document}
