\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\ \#1 \&\ \#2\ Solutions}
\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}
    In a sample of 20 people the times taken, in seconds, to solve a simple numerical puzzle were as follows:
    \\
    \\
    \(\begin{matrix}
        17 & 19 & 22 & 26 & 28 & 31 & 34 & 36 & 38 & 39 \\
        41 & 42 & 43 & 47 & 50 & 51 & 53 & 55 & 57 & 58 \\
    \end{matrix}\)
    \\

    \begin{enumerate}
        \item Calculate the mean and standard deviation of these times.
        \item In fact, 23 people attempted to solve this puzzle. However, 3 of them failed to solve it within the allotted time of 60 seconds, taking 62, 65 and 97 seconds respectively.  Calculate the interquartile range (IQR) of the times taken by all 23 people.
        \item Are there any outliers in the dataset?
    \end{enumerate}


    \solution

    \part{1}
    \\
    \textbf{Mean}
    \[
        \begin{split}
            \bar{x} &= \frac{1}{n} \sum_{i=1}^{n} x_i \\
            &= \frac{\left( 17 + 19 + 22 + 26 + 28 + 31 + 34 + 36 + 38 + 39 + 41 + 42 + 43 + 47 + 50 + 51 + 53 + 55 + 57 + 58 \right)}{20}  \\
            &= \frac{787}{20}\\
            &= 39.35
        \end{split}
    \]
    \\
    \textbf{Standard Deviation}

    \[
        \begin{split}
            s^2 &= \frac{\sum (x_i - \bar{x})^2}{n-1} =\frac{1}{n-1} \Bigr[ \sum x_i^2 - \frac{(\sum x_i)^2}{n} \Bigr]\\
            &= \frac{1}{19} \Bigr[ \sum x_i^2 - \frac{(\sum x_i)^2}{20} \Bigr]\\
            &= \frac{1}{19} \Bigr[ \sum x_i^2 - \frac{787^2}{20} \Bigr]\\
            &= \frac{1}{19} \Bigr[ (17^2 + 19^2 + \ldots + 58^2 ) - \frac{787^2}{20} \Bigr]\\
            &= 12.86
        \end{split}
    \]
    The mean is \framebox[1.5\width]{39.35} and the standard deviation is \framebox[1.5\width]{12.68}.

    \pagebreak

    \part{2}
    \textbf{Interquartile Range}

    Rearranging the data in ascending order, we get:\\\\
    17, 19, 22, 26, 28, 31, 34, 36, 38, 39, 41, 42, 43, 47, 50, 51, 53, 55, 57, 58, 62, 65, 97.\\

    Hence, Q1 = 31 and Q3 = 55.\\
    \[
        \begin{split}
            \text{IQR} &= \text{Q3} - \text{Q1} \\
            &= 55 - 31 \\
            &= 24
        \end{split}
    \]

    \part{3}
    \textbf{Outliers}

    The interquartile range is 24.\\
    $1.5 \times \text{IQR} = 36$.\\
    $Q3+1.5 \times \text{IQR} = 55 + 36 = 91$.\\
    $Q1-1.5 \times \text{IQR} = 31 - 36 = -5$.\\
    Hence, the outlier is 97, since it is greater than $1.5 \times \text{IQR}$ \\

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Consider the below tree diagram.
    \\
    \includegraphics{T1Q2.png}

    \begin{enumerate}[label=\roman*.]
        \item The probability $x$ represents (MCQ)?
              \begin{enumerate}
                  \item $P(A_1)$
                  \item $P(A_1|B_2)$
                  \item $P(B_2|A_1)$
                  \item $P(C_1|B_2 \cap A_1)$
              \end{enumerate}
        \item The probability $y$ represents (MCQ)?
              \begin{enumerate}
                  \item $P(B_2)$
                  \item $P(A_1|B_2)$
                  \item $P(B_2|A_1)$
                  \item $P(C_1|B_2 \cap A_1)$
              \end{enumerate}
        \item The probability $z$ represents (MCQ)?
              \begin{enumerate}
                  \item $P(C_1)$
                  \item $P(B_2|C_1)$
                  \item $P(C_1|B_2)$
                  \item $P(C_1|B_2 \cap A_1)$
              \end{enumerate}
        \item The circled node represents the event (MCQ)?
              \begin{enumerate}
                  \item $C_1$
                  \item $B_2\cap C_1$
                  \item $A_1 \cap B_2 \cap C_1$
                  \item $C_1|B_2\cap A_1$
              \end{enumerate}
              \text{[v. and vi. do not refer to the tree diagram above]}
        \item Let A and B be two events. Suppose that the probability that neither event occurs is 3/8. What is the probability that at least one of the events occurs?
        \item Let C and D be two events. Suppose P(C) = 0.5, $P(C \cap D) = 0.2$ and $P((C \cup D)\ complement) = 0.4$. What is P(D)?
    \end{enumerate}

    \pagebreak

    \solution

    \begin{enumerate}[label=\roman*.]
        \item The probability $x$ represents (MCQ)? $x = P(A_1)$
        \item The probability $y$ represents (MCQ)? $y = P(B_2|A_1)$
        \item The probability $z$ represents (MCQ)? $z =P(C_1|B_2 \cap A_1)$
        \item The circled node represents the event (MCQ)? $A_1 \cap B_2 \cap C_1$
        \item Since $P(A^c \cap B^c) = \frac{3}{8}$ and $P(A) +P(B) + P(A \cap B) = 1$,
            $P(\text{At least 1 event occurs}) = 1 - \frac{3}{8} = \frac{5}{8}$
    \end{enumerate}

    Given:\\
    $P(C) = 0.5$ \\
    $P(C \cap D) = 0.2$ \\
    $P((C \cup D)^c) = 0.4$\\
    $P(C \cup D) = 1-0.4 = 0.6$\\\\

    $P(C \cup D) = P(C)+P(D)-P(C\cap D)$\\
    $\rightarrow 0.6 = 0.5 + P(D) - 0.2 $\\
    $\rightarrow P(D) = 0.3$


\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    In a survey of 1929 students, the following data were obtained on “students’ first reason for application to the university in which they matriculated.”
    \\
    \includegraphics{T1Q3.png}
    \begin{enumerate}[label=(\alph*)]
        \item What is the probability that university quality is the first reason for a student to choose a university?
        \item For a full-time student, what is the probability that university quality is the first reason for choosing a university?
        \item Let A denote the event that a student is full-time, and let B denote the event that the student lists university quality as the first reason for applying. Are events A and B independent?
    \end{enumerate}

    \solution\\
    \part{a}

    $P(\text{quality}) = \frac{821}{1929} \approx 0.426$
    \\\\
    \part{b}

    $P(\text{quality}|\text{full-time}) = \frac{P(\text{quality} \cap \text{full-time})}{P(\text{full-time})} = \frac{\frac{421}{1929}}{\frac{890}{1929}} \approx 0.473$
    \\\\
    \part{c}

     A: A student is full-time\\
     B: the student lists university quality as the first reason for applying.\\
     Are events A and B independent?
     \\
     First, check if $P(B) = P(B|A)$\\
     $$
     \begin{align}
         P(B) &= P(\text{University Quality}) = \frac{821}{1929} = 0.426 \\
     P(B|A) &= P(\text{University Quality}|\text{full time student}) = \frac{421}{890} = 0.473\\
     \end{align}
     $$
     \\
     Since $P(B|!A) \neq P(B)$, the events are not independent.

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    A rare blood disease is found in 2\% of a certain population. A new blood test can correctly
    identify 96\% of the people with the disease and 94\% of the people without the disease.
    \begin{enumerate}[label=(\alph*)]
        \item What is the probability that a person who is tested positive by the blood test actually has the disease?
        \item What is the probability that a person who is tested negative by the blood test actually does not have the disease?
    \end{enumerate}

    \solution\\
    Let D = the person has the disease\\
    Let T = the person tests positive\\

    $P(D) = 0.02$\\
    $P(T|D) = 0.96$\\
    $P(T^c|D^c) = 0.94$\\

    \part{a}
    $$
    \begin{align}
    P(D|T) &= \frac{P(T|D)P(D)}{P(T|D)P(D) + P(T|D^c)P(D^c)}\\
           &=\frac{0.96 \times 0.02}{0.96 \times 0.02 + 0.06 \times 0.98}\\
           &= 0.246
    \end{align}
    $$

    \part{b}
    $$
    \begin{align}
    P(D^c|T^c) &= \frac{P(T^c|D^c)P(D^c)}{P(T^c|D^c)P(D^c) + P(T^c|D)P(D)}\\
           &=\frac{0.94 \times 0.98}{0.94 \times 0.98 + 0.04 \times 0.02}\\
           &= 0.999
    \end{align}
    $$


\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    A woman is pregnant with male twins. Twins may be either identical or fraternal (non-
    identical). In general, $\frac{1}{3}$ twins born are identical. Obviously, identical twins must be of the
    same sex; fraternal twins may or may not be. Assume that identical twins are equally likely
    to be both boys or both girls, while for fraternal twins all possibilities are equally likely:
    boy-girl, girl-boy, boy-boy, girl-girl. Given the above information, what is the probability
    that the woman’s male twins are identical?
    \\
    \\
    \solution\\

$$P(\text{identical}|BB) = \frac{P(BB|\text{identical})P(\text{identical})}{P(BB)} =
\frac{\frac{1}{2}\cdot \frac{1}{3}}{\frac{1}{2}\cdot \frac{1}{3} + \frac{1}{4}\cdot\frac{2}{3}} = \frac{1}{2}$$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    If a family had three kids, named Alice, Bob, and Carl. Assume that each is equally likely
    to be born; I.E., $\frac{1}{3}$ chance for each of them to be born first etc.
    \begin{enumerate}[label=(\alph*)]
        \item Find the probability that Alice is older than Bob, given that Alice is older than Carl.
        \item Is event “Alice is older than Bob” independent from event “Alice is older than C”?
    \end{enumerate}

    \solution\\
    A)\\
    Let A represent the event of Alice born\\
    Let B represent the event of Bob born\\
    Let C represent the event of Carl born

    $$
    \begin{align}
        P(A>B|A>C) &= \frac{P(A>B \cap A>C)}{P(A>C)}\\
                   &= \frac{\frac{1}{3}}{\frac{1}{2}}\\
                   &= \frac{2}{3}
    \end{align}
    $$

    B)\\
    They are not independent because $P(A>B|A>C) \neq P(A>B)$\\
\end{homeworkProblem}


\pagebreak

\begin{homeworkProblem}[7]
    A boy receives a school report card each week. He is given a special treat whenever his
    report indicates “Good behavior” \textbf{AND} “Excellent Homework”. His behavior is good with
    probability 0.6. When his behavior is good, he has a probability of 0.8 of doing excellent
    homework. When his behavior is not good, his probability of doing excellent homework
    is only 0.5.

    \begin{enumerate}[label=\alph*)]
        \item For a random week, calculate the probability that he will be given a special treat
        \item For a random Week, calculate the probability that his homework will be excellent but he will not be given a special treat
        \item For a random Week, calculate the probability that his homework will be excellent
        \item Given that his homework is excellent, calculate the conditional probability that he is NOT given a special treat.
    \end{enumerate}


    \solution
    \\
    Let G represent the event of good behavior\\
    Let E represent the event of excellent homework\\
    $E^c$ is the complement of E and $G^c$ is the complement of G\\

    A)\\
    "Good Behavior" and "Excellent Homework"\\
    $$P(G\cap E) = P(G)P(E|G) = 0.6 \times 0.8 = 0.48$$

    B)\\
    "Not Good behavior" AND "Excellent Homework"\\
    $$P(G^c \cap E) = P(G^c)P(E|G^c) = 0.4 \times 0.5 = 0.2$$

    C)\\
    "Excellent Homework"\\
    $$P(E) = P(G)P(E|G) + P(G^c)P(E|G^c) = 0.6 \times 0.8 + 0.4 \times 0.5 = 0.68$$

    D)\\
    "Not Good Behavior" given "Excellent Homework"\\
    $$P(G^c|E) = \frac{P(G^c \cap E)}{P(E)} = \frac{0.2}{0.68} = 0.294$$
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}[8]
    In an attempt to find the mean number of hours his tutorial classmates spent per day preparing for tutorials,
    John collected data from 10 of his friends in the tutorial group and found that the sample mean is 2.4 hours with a sample standard deviation of 0.8 hours.
    However, a day later he felt that the sample size is too small.
    So he collected data from another 5 of his friends and found that the sample mean is 2.0 hours with a sample standard deviation of 1.2 hours.
    \\
    Find the sample mean and sample standard deviation \underline{when these 2 sets of data are combined}.
    \\
    \\
    \solution\\
    Given:
    \[
        \begin{split}
            X &= \{x_1, x_2, \dots, x_{10}\} \\
            Y &= \{y_1, y_2, \dots, y_{5}\}\\\\
            \bar{x} &= \frac{\sum x_i}{10} = 2.4\\
            \sum x_i &= 10 \times 2.4 = 24 \\
            \bar{y} &= \frac{\sum y_i}{5} = 2.0 \\
            \sum y_i &= 5 \times 2.0 = 10 \\
            \text{new mean}\ \bar{z} &= \frac{\sum x_i + \sum y_i}{n_x + n_y} = \frac{24 + 10}{10+5} = 2.267\\ \\
        \end{split}
    \]
    \\
    Sample Standard Deviation can be used to figure out the missing values\\
    \[
        \begin{split}
            S_x^2 &= \frac{1}{10-1} \Bigr[\sum x_i^2 - \frac{(\sum x_i)^2}{10}\Bigl] = 0.8^2\text{, so } \sum x_i^2 = 9 \times 0.8^2 + \frac{24^2}{10} = 63.36\\
        S_y^2 &= \frac{1}{5-1} \Bigr[\sum y_i^2 - \frac{(\sum y_i)^2}{5}\Bigl] = 1.2^2\text{, so } \sum y_i^2 = 4 \times 1.2^2 + \frac{10^2}{5} = 25.76\\
        \text{new variance } s_z^2 &= \frac{1}{10+5-1} \Bigr[ \sum x_i^2 + \sum y_i^2 - \frac{(\sum x_i + \sum y_i)^2}{10+5} \Bigl] \\
                                   &= \frac{1}{14} \Bigr[63.36 + 25.76 - \frac{(24+10)^2}{15} \Bigl] = 0.86\\
        \text{new Standard Deviation } s_z &= \sqrt{s_z^2} = \sqrt{0.86} = 0.927
        \end{split}
    \]

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}[9]
    A certain family has 6 children, consisting of 3 boys and 3 girls.
    Assuming that all birth orders are equally likely,
    what is the probability that the 3 eldest children are the 3 girls?
    \\
    \\
    \solution
    \\
    $$
    \begin{align}
        \text{Probability that the 3 eldest are the 3 girls} &= \frac{3}{6} \times \frac{2}{5} \times \frac{1}{4}\\
                                                  &= \frac{6}{120}\\
                                                  &= 0.05
    \end{align}
    $$
    Note: Only one possible way the 3 girls can be the oldest
\end{homeworkProblem}

\pagebreak
\end{document}
