\documentclass{article}
\usepackage{techexpl}
\input{control}

\begin{document}

\thispagestyle{empty}


\begin{center}
\vspace{1.0in}
\Large\bf
Data Structures and Algorithms ---   CSCI 230 \\
Discrete Mathematics Overview --- Part A
\end{center}

\hdr{Introduction}

During the first three weeks of the semester we will cover some
techniques from discrete mathematics relevant to computer science in
general and algorithm analysis in particular.  This material is
somewhat more extensive than offered in Chapter~1 of the Weiss text.
It does not even begin to substitute for a course in discrete
mathematics, however.  Students, especially those interested in
graduate school in computer science, should consider taking a separate
discrete mathematics course during their undergraduate careers.


\hdr{Sets}

\privatenotes{Most of this will be review and we will move through it
quickly.} 

\begin{itemize}
\item A set is an {\bf unordered} collection of distinct objects
(called \emph{elements}).  These elements may be anything,
including other sets.

\item There are many special sets with special designations. {
\boldmath $Z$} is the set of integers. { \boldmath $N$ } is the set of
natural numbers (integers beginning with 0).  { \boldmath $R$ } or
$\Re$ is the set of real numbers.  The set with no elements, often
called the ``null set'' or the ``empty set,'' is denoted 
$\{ \}$.

\item The elements of a set may be specified in a number of ways.  The
simplest one to list the elements, e.g.,
\[
 V = \{ a, u, e, i, o \}.
\]
We use the notation $ a \in V$ to say ``$a$ is an element of $V$''.
Another way to specify the elements of a set is to describe them
logically using what's referred to as ``set-builder notation''.  For
example,
\[
S = \{ x \mid  \; x \in \text{\boldmath $R$} \; \text{and} \; 0 \leq x
\leq 1 \}
\]
is the set of \textbf{all} real numbers in the interval from 0 to 1
inclusive.


\item A set $S$ is a \emph{subset} of another set $T$ if and
  only if each element of $S$ is also an element of $T$.
  This is denoted by $ S \subseteq T $.

% \item The \emph{power set} of a set $S$, denoted by $ P(S) $,
%   is the collection of all subsets of $S$.

\item The \emph{cardinality} of a set $S$, denoted by $ | S | $,
  is the number of distinct elements of $S$.

% \item The \emph{Cartesian product} of two sets, $A$ and $B$, 
%   denoted by $A \times B$, is the set of all ordered pairs
%   $(a,b)$, where $ a \in A $ and $ b \in B $.
%   I.e.
%   \[  A \times B = \{ (a,b) \; | \; a \in A, b \in B \} \]

\item New sets may be formed from existing sets, $S$ and $T$, by a
  variety of operations, such as union  ($S \cup T$),
  intersection ($ S \cap T $), set difference ($ S - T $)
  and set complement $\overline{S}$.   Set complement requires the
  notion of a ``universal set'' $U$ from which set elements can be
  drawn.

  Most of these set operations should be familiar.  The only one that
  might be new is set difference:
\[ S-T = \{ x \mid x\in S \; \text{and} \; x \not\in T \}. \]

\item Two sets, $A$ and $B$, are said to be \emph{disjoint} if $A \cap
B = \{ \}$.
\end{itemize}

\hdr{In-class problems}

Work on these problems briefly.  Most should be straightforward.  We
will discuss the  solutions in class.
\begin{enumerate}
\item
Given $S = \{ a, b\}$ and $T = \{0, a, \{1,2\} \}$.
  \begin{enumerate}

  \item List the elements of $T$. 
    \label{listT}
      \answer{There are three elements: $0$, $a$, and $\{1, 2\}$.\\

%\extra{Note that $1$ and $2$ are \emph{not} considered elements of $T$.}
}

  \item List all subsets of $S$.

       \answer{The four subsets of $S$ are $\{\}, \{a\}, \{b\}, \{a,b\}$.

%\extra{Note that both the empty set and the set itself are
%considered subsets.}
}

  \item What is $|S|$?  \answer{$2$}

  \item What is $|T|$?  \answer{$3$}

  \item What are $S \cap T$  \answer{\{a\}}

        and $S - T$? \answer{\{b\}}

  \end{enumerate}

\overnew
\item
Let $S$ be the set of items on your shopping list and let $T$ be the
set of items you actually bought during a trip to the store.  Describe
each of the following in English.

  \begin{enumerate}

  \item $S \cap T$ \answer{The items that were on the list and I
  actually bought.}

  \item $T-S$ \answer{The items I bought that weren't on the list.}


  \item $S-T$ \answer{The items on the list that I failed to buy.}



  \end{enumerate}
\end{enumerate}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\hdr{Functions}
\label{here}
\begin{itemize}
\item A function, $f$, is a mapping from one set, $A$, called the
  \emph{domain}, to another set, $B$, called the \emph{co-domain},
  that associates {\bf each} element of $A$ with a {\bf single}
  element of $B$.
  We write this as
  \[  f \! : A \rightarrow B \]
  If $ a \in A$ and $f$ maps $a$ to $b $, we write $f(a) = b$.

\item The \emph{range} of $f$ is the set containing all $b \in B$ such that
$f(a)=b$ for some $a \in A$.

\overnew
\item Special functions of interest

  \begin{itemize}
  \item Floor:  $f(x) =  \lfloor x \rfloor$.  This is the largest
  integer less than or equal to x.

  \item Ceiling:  $f(x) =  \lceil x \rceil$.  This is the smallest
  integer greater than or equal to x.

  \item Factorial:  $f(n) = n!$.  Note that the domain of this function is
  the natural numbers.
  \end{itemize}

\overnew
\item Exponentiation (base $b$): $f(x) = b^x$.  Rules for
manipulation:
\begin{eqnarray*}
b^x b^y &= b^{x+y} \\
\frac{b^x}{b^y} &= b^{x-y} \\
(b^x)^y &= b^{xy} \neq b^{(x^y)} 
\end{eqnarray*}

\overnew
\item Logarithm (base $b>0$):  $f(x) = \log_b x$.  This means, $y =
\log_b x$ if $b^y = x$.  If $b$ is unspecificed, 2 is assumed.  Rules
for manipulation:
\begin{eqnarray*}
\log_a b &= \frac{\log_c b}{ \log_c a} \qquad \text{for $c >0$~~(Change of Base Law)} \\
\log xy &= \log x + \log y \\
\log (x^y) &= y \log x \neq (\log x)^y \\
\log x &< x \qquad \text{for all $x > 0$}
\end{eqnarray*}

\end{itemize}

\hdr{In-Class Problems on Functions}

\begin{enumerate}

\item What are
  \begin{enumerate}
  \item $5!$  \answer{$120$} 

  \item $\lceil 2 \rceil$,  $\lceil 2.1 \rceil$,  $\lceil -2.1 \rceil$, 

    \answer{$2, 3, -2$}

  \item $\lfloor 2 \rfloor$,  $\lfloor 2.1 \rfloor$,  $\lfloor -2.1
  \rfloor$?

     \answer{$2, 2, -3$}

  \end{enumerate}

%% \item Write a C++ function to compute $\lfloor x \rfloor$ using the
%% \verb$(int)$ operator to convert from \verb$float$ or \verb$double$
%% to \verb$int$. 

\item What is the derivative of $\log_b x$?  

\hint{Recall that the derivative of the natural logarithm is $1/x$.\\

\continue{Use the Change of Base Law given above:
\[
\log_a b = \frac{\log_c b}{ \log_c a} \qquad \text{for $c >0$}
\]
}
}

\answer{
\[ 
 \frac{d}{dx}(\log_b~ x) = \frac{d}{dx}(\frac{\log_e~ x}{\log_e~ b}) = 
  \frac{1}{\log_e~ b}~\frac{d}{dx}(\log_e~ x) 
\]
\[
=  \frac{1}{x~ \log_e~ b}
\]
}
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\hdr{Summations}

\begin{itemize}
\item A summation is a short-hand notation to describe the addition of
the terms of a sequence:
\[ \sum_{i=m}^n f(i) = f(m) + f(m+1) + f(m+2) + \ldots + f(n) \]
The variable $i$ is called the index variable.  Most often $m=0$ or
$m=1$.  Sometimes a summation is easiest to think about by thinking
about the \verb$for$ loop you would write to calculate it.

\item Special summation formulas:
\begin{eqnarray*}
\sum_{i=0}^n 2^i &= 2^{n+1} - 1 \\
\sum_{i=0}^n a^i &= \frac{a^{n+1} - 1}{a - 1} \qquad \text{for $a\neq 1$} \\
\sum_{i=1}^n i &= \frac{n (n+1)}{2} \\
\sum_{i=1}^n i^2 &= \frac{n (n+1)(2n+1)}{6} \\
\sum_{i=1}^n \frac{1}{i} &\approx \log_e n
\end{eqnarray*}

\newpage
\item Simple rules for manipulating summations.  These rules may
perhaps be best understood by writing the summation out long hand and
then using standard rules of algebra.
\begin{eqnarray*}
\sum_{i=m}^n [ f(i) + g(i) ]
   &= \left( \sum_{i=m}^n f(i) \right) \;+\; \left( \sum_{i=m}^n g(i)
   \right) \\
\sum_{i=m}^n  a \cdot f(i ) &= a \cdot \sum_{i=m}^n  f(i ) \\
\sum_{i=m}^n  a &= a \cdot (n-m+1) \\
\sum_{i=m}^n  f(i ) &= \sum_{i=0}^n  f(i ) - \sum_{i=0}^{m-1} f(i) \\
\sum_{i=m}^n  f(i ) &= \sum_{j=0}^{n-m} f(j+m) 
\end{eqnarray*}
\overnew
In these formulas, $a$ stands for an arbitrary but fixed constant
(i.e.\ something that doesn't change when $i$ changes).
\end{itemize}


\hdr{Problems on summations}

\begin{enumerate}

\item Write each of the following as a summation.
  \begin{enumerate} 
  \item $5 + 10 + 15 + 20 + \ldots + 1000$

      \answer{$\sum_{i=1}^{200} 5i$}

  \item $3 + 8 + 13 + 18 + \ldots + 98$

      \answer{$\sum_{i=0}^{19} (3 + 5i)$}


  \item $4 + 8 + 16 + 32 + \ldots + 1024$

      \answer{$\sum_{i=2}^{10} 2^i$}

  \end{enumerate}


\overnew
\item Derive a formula for each of the following that does not involve
a summation and does not involve $i$.  Use the rules for manipulation
and the special formulas.
  \begin{enumerate}
  \item  $\displaystyle \sum_{i=1}^n 4i$.

    \answer{$4 \sum_{i=1}^n i = 2n(n+1)$.}

  \item  $\displaystyle \sum_{i=3}^n (5 i + 4) $.

    \answer{\begin{eqnarray*}
     5 \sum_{i=3}^n i + 4 \sum_{i=3}^n 1 &= & 
                  \frac{5n}{2}(n+1) - (5 + 10) + 4(n - 2) \\
       & = & \frac{1}{2}(5n^2 + 13n - 46).
     \end{eqnarray*}
    }

  \item  $\displaystyle \sum_{j=0}^k (4^j + k)$.

    \answer{\begin{eqnarray*}
       \sum_{j=0}^k 4^j + k \sum_{j=0}^k 1 & = & \frac{4^{k+1}-1}{3} 
            + k(k + 1) 
     \end{eqnarray*}
    }
        

  \item  $\displaystyle \sum_{i=0}^N (2 + \sum_{j=0}^i j )$

    \firststep{\begin{eqnarray*}
       2 \sum_{j=0}^N 1 + \sum_{i=0}^N \frac{i(i+1)}{2} 
          & = & 2(N+1) + \frac{1}{2}\sum_{i=0}^N i^2 
              + \frac{1}{2}\sum_{i=0}^N i \\
     \end{eqnarray*}
    

    \continue{\begin{eqnarray*}
          & = & 2(N+1) + \frac{1}{12}N(N+1)(2N+1) + \frac{1}{4} N(N+1) \\
          & = & 2N+2 + \frac{1}{12}(2N^3+3N^2+N) + \frac{1}{4}N^2 +  \frac{1}{4}N\\
          & = & \frac{1}{6}N^3 + \frac{1}{2}N^2 + \frac{7}{3}N + 2
     \end{eqnarray*}
     }
    }  

  \end{enumerate}

\overnew
\item (Extra challenge!) Derive a formula for the following that does not
involve a summation:
\[
  \sum_{i=1}^N \frac{i}{2^i}.
\]
Hint:  use the technique given in class for proving that
\[  \sum_{i=0}^n a^i = \frac{a^{n+1} - 1}{a - 1}. \]
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\hdr{Proofs}

\begin{itemize}

\item A proof is a clear, logical demonstration of the truth of an
assertion based on previously known facts (established propositions,
lemmas and theorems).

\overnew
\item In writing a proof, the first step is to carefully determine
what the assertion says, including the meanings of all terms used.

For example, you cannot prove that 2 is the only even prime number
without understanding what it means for a number to be ``even'' and to
be ``prime''.

Once you understand what is to be proved, the next step
is to write the actual proof.  This is a bit of an art form, which we
will not have time to investigate thoroughly.  But, \ldots

\overnew
\item Proof techniques we will explore:
  \begin{itemize}
  \item Direct proof.  Starting from the assumptions --- e.g.\ $n$ is
  an even positive integer --- construct a series of deductions
  leading to the claim --- e.g. $n$ is not prime.   

  \item Proof by example or counter-example.  This is acceptable when
  proving that there is a member of a set satisfying an assertion, or
  when proving that not all members of a set satisfy an assertion.
  But it is not possible to use this proof technique to prove
  that all members of an infinite set satisfy an assertion.

\overnew
  \item Proof by contradiction.  This is done by assuming that the
  assertion to be proved is false and showing that the assumption
  leads to a statement that must be both true and false (a
  contradiction).

 \item Proof by induction.  This technique is closely related to
 data structure and algorithm analysis and is covered in detail below.
 \end{itemize}

\privatenotes{Example to prove (by contradiction):  At least one of
$a_1, a_2, \ldots, a_n$ is greater than or equal to the average of
these values.}

\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\hdr{In-Class Exercises on Proofs}

\begin{enumerate}
\item Is it true that $n^3 > 2^n$ for all integers $n>1$?
Prove your result.

  \answer{The assertion is false, because for $n = 10$, $n^3 = 1000$
and $2^n = 1024$.  We say that $n = 10$ is a counterexample
to the assertion.  (Any value of $n \geq 10$ can serve as a
counterexample.)}  

\item Prove that 2 is the only even prime number.

  \answer{Proof: By contradiction.  Let $p$ be a prime $>2$ and
suppose $p$ is even.  Then $p = 2k$ for some $k > 1$, hence $p$ is
the product of two factors neither of which is $1$, contradicting
the assumption it was prime.}



\end{enumerate}

\buttonbox{\docLink{notes1b.tex}{Continue to \emph{Part B}}}

\end{document}

