% This is a TeX file
% It is essentially a programming language for mathematics documents
% You can ignore this first portion of the file, as it is essentially a bunch of "include" statements.
\documentclass[10pt]{article}

\usepackage{pictex, latexsym, graphicx,amsmath,amssymb,amsbsy,amsfonts,amsthm,verbatim}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage{fancyhdr}
\usepackage{array}

\usepackage{algorithm,algorithmic}
\usepackage{multirow}

\setlength{\parskip}{0.5em}
\setlength{\parindent}{0em}
\setlength{\voffset}{-0.5in}
\setlength{\headsep}{0.25in}

% The following denotes a counter for the problems.
\newcounter{problem}
\newcommand{\problem}{\textbf{Problem \refstepcounter{problem}.}}

% These are macro shortcuts! Helpful!
\def\vu{\mathbf{u}}
\def\vx{\mathbf{x}}
\def\vy{\mathbf{y}}
\def\vz{\mathbf{z}}
\def\vb{\mathbf{b}}
\def\vv{\mathbf{v}}
\def\vw{\mathbf{w}}

\renewcommand{\implies}{\rightarrow}
%\newcommand{\lnot}{\neg}
\renewcommand{\lor}{\vee}
\renewcommand{\land}{\wedge}
\newcommand{\xor}{\oplus}
\newcommand{\symmdiff}{\triangle}
\renewcommand{\iff}{\leftrightarrow}
\newcommand{\TRUE}{\mathbf{T}}
\newcommand{\FALSE}{\mathbf{F}}
\newcommand{\universe}{\mathcal{U}}


\def\N{\mathbb{N}}
\def\Q{\mathbb{Q}}
\def\C{\mathbb{C}}
\def\Z{\mathbb{Z}}
\def\R{\mathbb{R}}
\def\cP{\mathcal{P}}



\begin{document}
\pagestyle{fancyplain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOW you can start typing your text that will appear in the PDF!!!

% Note that anything after a '%' is a comment!

% Anything immediately after a '\' is a command. 
% Some denote formatting, some are for special characters.
% The '$' symbol starts and ends "math mode". Use this only for mathematical statements
% In math mode, any sequence of letters is meant to be a list of variables, so use "\sin x" for the sine of x, which will look much different from "sin x"

\lhead{}
\rhead{}
\chead{COM S 330 --- Lecture Notes --- Week of Mar 23--27}

\renewcommand{\arraystretch}{1.25}



\section{Monday, March 23}

\subsection{Rosen 6.5: Generalized Permutations and Combinations}

\textbf{Reading:} Rosen 6.5,  Ducks 7.1--7.4, LLM 14.1, 14.4, 14.5.2, 14.6

Recall that an \emph{$r$-permutation} from a set $A$ of $n$ elements is an $r$-tuple $(a_1,\dots,a_r)$ of distinct entries from the set $A$.
Thus, we can ``select'' the first element, then the second, and so on.
At every step, we are pulling the element out of the ``bag'' that is the set $A$, as we will not want to repeat an element.

What if we want to allow a repetition?

\textbf{Thm:} The number of $r$-tuples from a set $A$ of size $n$ is $n^r$.

\begin{proof}
By the strict product rule, $|A^r| = |A|^r = n^r$.

OR: We select a tuple $(a_1,\dots,a_r)$ by selecting each $a_i$ from $A$ in order; we allow repetition, so there are $n$ choices for each $a_i$.
\end{proof}

This is not terribly interesting! Let's do something else!

Recall that an \emph{$r$-combination} from a set $A$ of $n$ elements is a subset $S \subseteq A$ where $|S| = r$.
Essentially, we selected $r$ things from the set $A$, and we did not allow repeats, so we had ``removed'' the elements from the bag.
What if we allow repetition?

In order to allow repetition, we need the idea of a \emph{multiset}.
A \emph{multiset} is a collection of objects and each object is associated with a \emph{multiplicity} (a nonnegative integer).
Thus, the multiset containing $1$ once, $2$ twice, and $5$ three times can be denoted $\{1, 2, 2, 5, 5, 5\}$.
This differs from the permutations (with repetition) in that order does not matter.
That is, $\{1, 2, 2, 5, 5, 5\} = \{ 5, 2, 1, 5, 2, 5\}$.
The \emph{size} of a multiset is the sum of the multiplicities.

If we follow our usual counting process, then what happens?
We have $n$ possibilities for each element of our multiset, but we have a problem!
Sets with $r$ distinct elements are counted $r!$ times.
Sets with $r-1$ distinct elements are counted $\frac{r!}{2}$ times.
Sets with $r-2$ distinct elements are counted $\frac{r!}{3!}$ times (if one item appears three times) or $\frac{r!}{2\cdot 2}$ (if two items each appear twice).
This is complicated!

We need to count in a different way.

Instead: let's count by making a different set of decisions.
For a multiset of size $r$, we must make $r$ selections from our set $A$ of size $n$.
Instead of filling $r$ spots with some objects from the set $A$, then worrying about order, we will instead take $r$ ``tokens'' and place them on some of the elements of $A$.

If $A = \{ a_1, \dots, a_n\}$, then we can create a ``box'' for $a_i$.
To create a multiset $M$, take $r$ tokens, and put each into one box.
Boxes can hold multiple tokens.
After this process is complete, we can let $M$ be the multiset where $a_i$ appears with multiplicity given by the number of tokens in the $i$th box.

Again, if we followed the process step-by-step, we would run into issues with the order that the tokens were placed into each box!
We will instead count the number of end results directly instead of following the step-by-step process.

Think about our $n$ boxes in a slightly different way: There is one long box with $n-1$ dividers (splitting the box into $n$ spaces) and then the tokens are placed in the big box, between some dividers.
At the end, let's look from one side of the box to the other, looking for ``token'' or ``divider.''
We will see a list of $r$ tokens and $n-1$ dividers, giving $n+r-1$ total objects, but $r$ of them are tokens.


\textbf{Stars and Bars Theorem:} There are $\binom{n+r-1}{r} = \binom{n+r-1}{n-1}$ ways to:
\begin{itemize}
\item Select a multiset of size $r$ from a set of size $n$.
\item Place $r$ indistinct objects into $n$ distinct boxes.
\item Binary strings with exactly $r$ 0's and exactly $n-1$ 1's.
\end{itemize}

\begin{proof}
Note that we can build a multiset of size $r$ by placing $r$ indistinct tokens into $n$ distinct boxes (corresponding to the elements of the set).
Thus, let us count the number of ways to place $r$ indistinct objects into $n$ distinct boxes.
This is the same as the number of binary strings with exactly $r$ 0's and exactly $n-1$ 1's, as when we have $r$ objects in $n$ boxes we can use $n-1$ dividers between the boxes, then look through the boxes; when we see an object, we place a 0 in the string (a star); when we see a divider, we place a 1 in the string (a bar).
This results in $r$ 0's and $n-1$ 1's.
Note that we can reproduce the placement of objects in boxes from such a binary string, so the counts are the same.

Let us first notice that given a binary string with exactly $r$ 0's and exactly $n-1$ 1's, we have $n+r-1$ total positions in the string.
Exactly $r$ of these positions represent 0's, and the other $n-1$ represent $1$'s.
Thus, there are $\binom{n+r-1}{r}$ ways to select the positions that will be 0.
Equivalently, there are $\binom{n+r-1}{n-1}$ ways to select the positions that will be 1.
\end{proof}

\subsubsection{Objects and Boxes}

\textbf{Distinguishable Objects and Distinguishable Boxes}

\textbf{Thm:} The number of ways to distribute $n$ distinguishable objects into $k$ distinguishable boxes so that $n_i$ objects are placed into box $i$ is \[ \frac{n!}{n_1! n_2! \cdots n_k!}.\]

\begin{proof}
Permute the objects, then take the first $n_1$ for box 1, the next $n_2$ for box 2, and so on.
There are $n_i!$ ways that each box can be filled.
Thus, we divide by $n_1! n_2!\cdots n_k!$ as this is how many times each arrangement of objects into boxes appears.
\end{proof}


\textbf{Cor:} The number of different permutations of $n$ objects, where there are $n_1$ indistinguishable objects of type 1, $n_2$ indistinguishable objects of type 2, $\dots$, and $n_k$ indistinguishable objects of type $k$, is \[ \frac{n!}{n_1! n_2! \cdots n_k!}.\]


\textbf{Indistinguishable Objects and Distinguishable Boxes}

This is where we use Stars + Bars!


\textbf{Distinguishable Objects and Indistinguishable Boxes}

\textbf{Ex:} How many ways can we place four different cookies onto three indistinguishable plates, where each plate can contain any number of cookies?

\textbf{A:} 14

\textbf{Stirling numbers of the second kind:} $S(n,k)$ is the number of ways of partitioning $n$ objects into $k$ indistinguishable boxes.


\textbf{Indistinguishable Objects and Indistinguishable Boxes}

\textbf{Ex:} How many ways can we represent a number $n$ as the sum of $k$ natural numbers? (Here, order does not matter in the sum!)

The number 5 can be represented as a sum of 3 natural numbers in four ways:
\[
	5 = 5 + 0 + 0 = 4 + 1 + 0 = 3 + 1 +1 = 2 + 2 + 1
\]
The number 6 can be represented as a sum of 3 natural numbers in 7 ways:
\[
	6 = 6 + 0 + 0 = 5 + 1 + 0 = 4 + 2 + 0 = 4 + 1 + 1 = 3 + 3 + 0 = 3 + 2 + 1 =  2 + 2 + 2.
\]
Such an arrangement is called a \emph{partition} of the number.
Here, we are placing $n$ objects (the 1's that are summed to make $n$) into $k$ indistinguishable boxes (the numbers we sum).
The boxes are indistinguishable since we reorder the numbers to be in nonincreasing order.

\textbf{Recommended Homework.} Rosen 6.5: 9--16, 17--19, 21--26, 28, 30--35, 39--40, 44, 45, 50, 51, 61, 63--64


\clearpage
\section{Wednesday, March 25}


\subsection{Rosen 10.1: Graphs and Graph Models}

\textbf{Reading:} Rosen 10.1,  Ducks 3.1, 3.5, LLM 

\textbf{Examples of Graphs in the Real World:}

\textbf{Facebook:} People are dots, draw a line between dots if they are friends. Do not draw a line if they are not friends. [See ``acquaintanceship and friendship graphs'' in the book.]

\textit{Questions:} How large a group of people are all friends with each other? Given two people, how many ``handshakes'' are they away from each other? People are friends with people they know from family, high school, college, and work; can you tell which people are in a group together?\\

\textbf{Twitter:} People are dots, draw an arrow from dot $a$ to dot $b$ if $b$ follows $a$ (so tweets from $b$ are ``sent'' to $a$). [See ``influence graph'' in the book.]

\textit{Questions:} Which person has the most followers? I use Twitter for personal use, entertainment, and to follow researchers in math and computer science; Can you guess which are which by looking at the relationships between the people I follow? Suppose a political tweet has a 1\% chance of being retweeted; what is the likelyhood of the tween being retweeted over 1,000 times?\\

\textbf{6 degrees of Kevin Bacon:} Let actors on IMDB be dots. Draw a line between dots if they acted in a movie together. How many movies do we need to use to get from any actor to Kevin Bacon? Is it at most 6?\\

\textbf{Erd\H{o}s Numbers:} Let mathematicians be dots. Draw a line between dots if they co-authored a paper. How many papers do we need to use to get from a Mathematician to Paul Erd\H{o}s? (Erd\H{o}s has number 0; over 250 people have number 1; my number is 2) [See ``Collaboration Graph'' in the book.]\\

\textbf{Scheduling:} Let faculty in the Computer Science department be dots. This is a contentious department, and some people cannot stand each other. Place a line between dots if those two faculty cannot be in the same room at the same time.

\textit{Questions:} If the Department Chair wants to meet with groups of faculty in the fewest number of timeslots, how can we schedule the faculty to meeting times such that the meetings will stay cordial? Observe: if there are $k$ people who all hate each other, then we will need at least $k$ meeting times! Is this always the best bound?\\

\textbf{Road Maps:} Let cities be dots. Draw a line between dots if there is a road between these cities. Label the line with the time it takes to drive that distance.

\textit{Questions:} How long does it take to drive between two cities, using the shortest possible route? How long does it take to leave your hometown, visit all of the cities exactly once, and return home?\\

\textbf{Computer Networks:} Let computers and routers be dots. Put a line between dots if those machines are connected by a network connection (wired or wireless). Label each line with the bandwidth.

\textit{Questions:} Suppose I want to send a message from computer $s$ to computer $t$; if I can split the message into multiple tiny pieces, how can I route the pieces through the network in order to send the full message to $t$ as quickly as possible? Keep in mind that there is some lag time for the message pieces to be processed at each node.\\

\textbf{Internet Search:} Let web pages be dots; label the dots with their textual content. Put an arrow from one dot to another if there is a link on that page to the other. 

\textit{Question:} If I want the most-important web page about ``Mathematicians near Ames, IA'' I want to find a page that doesn't just have the most instances of "mathematician" and ``ames'' but I want a page that other web pages link to, since they find it important. How can I detect which pages are the most important? [See ``The Web Graph'' in the book; see ``PageRank algorithm'' on Wikipedia.]

\subsubsection{Formal Definition of a Graph}

\textbf{Def:} A \emph{graph} $G = (V,E)$ is a pair of sets $V$ and $E$ where $V$ is a set of \emph{vertices} and $E$ is a subset of the unordered pairs of $V$ (define $\binom{V}{2} = \{ \{u, v\} : u, v \in V, u \neq v \}$ and let $E \subseteq \binom{V}{2}$.). A pair $\{u,v\}$ is an \emph{edge} if $\{u,v\} \in E$; we will shorten our notation to use $uv$ to represent $\{u,v\}=\{v,u\}$. 

(The definition above is sometimes called a \emph{simple graph} as there are more complicated definitions that allow multiple edges ($E$ is a multiset), or loops ($E$ can contain $\{v,v\}$ as an edge). We will avoid these at all costs!]

\textbf{Def:} A \emph{directed graph} $G = (V,E)$ is a pair of sets $V$ and $E$ where $V$ is a set of \emph{vertices} and $E$ is a subset of the ordered pairs of $V$ (let $E \subseteq \{ (u,v) : u, v \in V, u\neq v\}$.). A pair $(u,v)$ is a \emph{(directed) edge} if $(u,v) \in E$; we will shorten our notation to use $\stackrel{\rightarrow}{uv}$ or $u \to v$ to represent $(u,v)$. 

\textbf{Examples of Common Graphs:}
\begin{itemize}
\item The Complete Graph $K_n$ is the graph with vertex set $V = \{ 1, \dots, n\}$ and $E = \binom{V}{2}$.
\item The Empty Graph $\overline{K_n}$ is the graph with vertex set $V = \{1,\dots, n\}$ and $E = \varnothing$. (Note: empty edge set, not empty vertex set.)
\item The Cycle Graph $C_n$ is the graph with vertex set $V = \{1,\dots,n\}$ and $E = \{ \{1,2\}, \{2,3\}, \dots, \{n-1,n\}, \{n,1\} \}$.

\end{itemize}




\clearpage
\section{Friday, March 27}

\subsection{Rosen 10.2: Graph Terminology and Types of Graphs}

\textbf{Reading:} Rosen 10.2,  Ducks  3.5, LLM 

Let $G$ be a graph with vertex set $V(G)$ and edge set $E(G)$.

\textbf{Examples of Common Graphs:}
\begin{itemize}
\item The Complete Graph $K_n$ is the graph with vertex set $V = \{ 1, \dots, n\}$ and $E = \binom{V}{2}$.
\item The Empty Graph $\overline{K_n}$ is the graph with vertex set $V = \{1,\dots, n\}$ and $E = \varnothing$. (Note: empty edge set, not empty vertex set.)
\item The Cycle Graph $C_n$ is the graph with vertex set $V = \{1,\dots,n\}$ and $E = \{ \{1,2\}, \{2,3\}, \dots, \{n-1,n\}, \{n,1\} \}$.
\item The Wheel Graph $W_n$ is the graph given by taking the cycle $C_n$ and adding a vertex $0$ that is adjacent to all vertices $i$ with $1 \leq i \leq n$.
\item The $k$-dimensional hypercube $Q_k$ is the graph with vertex set $V$ given by binary strings of length $k$ and two binary strings are adjacent if they differ in exactly one coordinate.

\item The Complete Bipartite Graph $K_{n,m}$ is the graph with vertex set $V = X \cup Y$ where $X = \{x_1,\dots,x_n\}$, $Y = \{y_1,\dots,y_m\}$, $X\cap Y = \varnothing$ and the edge set $E$ is the set $\{ x_iy_j : i \in \{1,\dots,n\}, j\in \{1,\dots,m\}\}$.
\end{itemize}



\textbf{Def:} Two vertices $u$ and $v$ are \emph{adjacent} if the pair $uv$ is an edge in $E(G)$.

\textbf{Def:} For an edge $e = uv \in E(G)$, the vertices $u$ and $v$ are \emph{endpoints} of $e$.

\textbf{Def:} A vertex $v$ and an edge $e$ are \emph{incident} if $v$ is an endpoint of $e$.

\textbf{Def:} The \emph{neighborhood} of a vertex $v$ is the set of adjacent vertices, denoted $N(v) = \{ u : uv \in E(G) \}$.

\textbf{Def:} The \emph{degree} of a vertex $v$ is the size of $N(v)$; equivalently, it is the number of vertices adjacent to $v$.

\textbf{Def:} A vertex is \emph{isolated} if it has degree zero; a vertex is a \emph{pendant} if it has degree one.

\textbf{Degree-Sum Formula:} (also called the Handshaking Theorem) Let $G$ be a graph with vertex set $V(G)$ and edge set $E(G)$.
Then,
\[
	2|E(G)| = \sum_{v \in V(G)} d(v).
\] 
\vspace{-1em}
\begin{proof}
Let us count edges by looking at vertices.
Each vertex is incident to $d(v)$ edges.
Every edge is incident to two vertices.
Thus, $\sum_{v\in V(G)}d(v)$ counts each edge exactly twice, so the sum is $2|E(G)|$.
\end{proof}

\textbf{Thm:} A graph has an even number of vertices of odd degree.


\textbf{Def:} A graph $G$ is \emph{bipartite} if $V(G)$ can be partitioned into two disjoint sets $V(G) =  X \cup Y$ where each edge in $E(G)$ has one endpoint in $X$ and the other endpoint in $Y$. The union $X \cup Y$ is called a \emph{bipartition}.

\textbf{Thm:} The cycle $C_n$ is bipartite if and only if $n$ is even.

\vspace{-1em}
\begin{proof}
If $n$ is even, then let $X$ be the set of odd numbers and $Y$ the set of even numbers.
The edges $\{1,2\}, \{2,3\}, \dots, \{n-1,n\}$ have one endpoint in each of $X$ and $Y$.
Also, since $1$ is odd and $n$ is even, the edge $\{n, 1\}$ has one endpoint in $X$ and one endpoint $Y$.
Thus, $X \cup Y$ is a bipartition for $C_n$ when $n$ is even.

Let $n$ be an odd number and suppose (for the sake of contradiction) that $C_n$ has a bipartition $V(C_n) = X \cup Y$.
The number 1 is in one of $X$ or $Y$; without loss of generality we can assume $1 \in X$.
Note that if $i$ is in $X$ for some $i < n$, then since $\{i,i+1\}$ is an edge, $i+1$ must be in $Y$.
Note that if $i$ is in $Y$ for some $i < n$, then since $\{i,i+1\}$ is an edge, $i+1$ must be in $X$.
Thus $X$ is the set of odd numbers and $Y$ is the set of even numbers.
However, this means that both $1$ and $n$ are in $X$, but then the edge $\{n, 1\}$ has both endpoints in $X$ and hence $X \cup Y$ is not a bipartition, a contradiction!
Thus, $C_n$ is not bipartite as no bipartition exists.
\end{proof}

\textbf{Thm:} The $k$-dimensional hypercube $Q_k$ is bipartite.

\vspace{-1em}
\begin{proof}
Let $X$ be the set of binary strings with an even number of 1's.
Let $Y$ be the set of binary strings with an odd number of 1's.
All edges connect strings with one different coordinate, so the number of 1's changes by exactly one.
Hence strings in $X$ are adjacent only to strings in $Y$, and vice-versa.
Thus $X \cup Y$ is a bipartition.
\end{proof}





\end{document} 
