\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{xcolor}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{tikz}
%\usepackage{pgfplots}
\tikzstyle{ball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=1.3pt]
%\usetikzlibrary{arrows.meta}
%\tikzset{>={Latex[length=2mm,width=1.5mm]}}

%\usepackage{graphicx}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage{enumitem}
\setlist[enumerate]{leftmargin=*}

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Math 372 lecture for Monday, Week 1}
\bigskip

For administrative details, see our course homepage:
\begin{center}
  \url{http://people.reed.edu/~davidp/372/}.
\end{center}

{\bf Topic I. Walks in Graphs.}
\medskip

{\color{red} Question.} How many walks are there of length~$\ell$ between two
given vertices of a graph~$G$?  (The {\em length} is the number of edges traversed.)
\medskip

{\bf Note.} Throughout today's lecture,~$G$ will be a simple graph with
vertices~$v_1,\dots,v_p$.

{\bf Example.} Consider the question on~$G=C_4$, the cycle graph on four
vertices;
\begin{center}
  \begin{tikzpicture}
    \node[ball, label={below left:$v_1$}] (1) at (0,0) {};
    \node[ball, label={below right:$v_2$}] (2) at (1,0) {};
    \node[ball, label={above right:$v_3$}] (3) at (1,1) {};
    \node[ball, label={above left:$v_4$}] (4) at (0,1) {};
    \draw (1)--(2)--(3)--(4)--(1);
    \begin{scope}[xshift=2.5in]
      \node at (0,0) {$\displaystyle
	\begin{array}{c|l}
	  \text{length}&\text{walks from~$v_1$ to $v_3$}\\\hline
	  0&\text{---}\\
	  1&\text{---}\\
	  2&v_1v_2v_3, v_1v_4v_3\\
	  3&\text{---}\\
	  4&v_1v_2v_1v_2v_3, v_1v_2v_1v_4v_3, v_1v_2v_3v_2v_3 \\
	  &v_1v_2v_3v_4v_3, v_1v_4v_1v_2v_3, v_1v_4v_1v_4v_3 \\
	  &v_1v_4v_3v_2v_3,v_1v_4v_3v_4v_3
	\end{array}
      $};
    \end{scope}
  \end{tikzpicture}
\end{center}

{\bf Definition.} The {\color{red} adjacency matrix} for~$G$ is the~$p\times p$
matrix~$A$ given by
\[
  A_{ij}=
  \begin{cases}
    1&\text{if~$G$ has an edge from~$v_i$ to~$v_j$,}\\
    0&\text{otherwise}.
  \end{cases}
\]

{\bf Proposition.} Let~$A$ be the adjacency matrix for~$G$.  Then the number of
walks of length~$\ell$ in~$G$ from~$v_i$ to~$v_j$ is~$(A^{\ell})_{ij}$.
\smallskip

{\bf Proof.} We prove this by induction.  The base case,~$\ell=0$, is trivial.
For~$\ell\geq1$, say~$A^{\ell-1}=B=(b_{mn})$.  Then
\[
  (A^{\ell})_{ij}=(BA)_{ij}=\sum_{k=1}^{p}B_{ik}A_{kj}.
\]
By induction,
\[
  b_{ik} = \text{\# walks from~$v_i$ to~$v_k$ of length~$\ell-1$}.
\]
We also have
\[
  a_{kj}=
  \begin{cases}
    1&\text{if~$G$ has an edge from~$v_k$ to~$v_j$,}\\
    0&\text{otherwise}.
  \end{cases}
\]
Each walk from~$v_i$ to~$v_j$ of length at least one must pass through some
vertex~$v_k$ to~$v_j$ in its final step, and the final edge must be~$\left\{
v_k,v_j \right\}$.  The result follows.
\hfill$\Box$

\medskip

{\bf Example.} Consider $G=C_4$, again.  Here are some powers of the adjacency
matrix:
\begin{center}
  \begin{tikzpicture}
    \node[ball, label={below left:$v_1$}] (1) at (0,0) {};
    \node[ball, label={below right:$v_2$}] (2) at (1,0) {};
    \node[ball, label={above right:$v_3$}] (3) at (1,1) {};
    \node[ball, label={above left:$v_4$}] (4) at (0,1) {};
    \draw (1)--(2)--(3)--(4)--(1);
    \begin{scope}[yshift=-1.0in]
      \node at (0,0) {$\displaystyle
	A=
	\left(\begin{array}{cccc}
	    0&1&0&1\\
	    1&0&1&0\\
	    0&1&0&1\\
	    1&0&1&0
	\end{array} \right),
	\qquad
	A^2=
	\left(\begin{array}{cccc}
	    2 & 0 & 2 & 0 \\
	    0 & 2 & 0 & 2 \\
	    2 & 0 & 2 & 0 \\
	    0 & 2 & 0 & 2
	\end{array} \right),
	\qquad
	A^3=
	\left(\begin{array}{cccc}
	    0 & 4 & 0 & 4 \\
	    4 & 0 & 4 & 0 \\
	    0 & 4 & 0 & 4 \\
	    4 & 0 & 4 & 0
	\end{array} \right),
      $};
    \end{scope}
    \begin{scope}[xshift=-2in,yshift=-2.0in]
      \node at (0,0) {$\displaystyle
	A^4=
	\left(\begin{array}{cccc}
	    8 & 0 & 8 & 0 \\
	    0 & 8 & 0 & 8 \\
	    8 & 0 & 8 & 0 \\
	    0 & 8 & 0 & 8
	\end{array} \right).
      $};
    \end{scope}
  \end{tikzpicture}
\end{center}
Compare the~$1,3$-entries in the above matrix with walks displayed in the
previous example.
\medskip

{\bf Theorem.} A real $p\times p$ symmetric matrix~$A$ has~$p$ orthonormal
eigenvectors, i.e., there exist $u_1,\dots,u_p\in\R^p$ with
\[
  u_i\cdot u_j=\delta(i,j)=
  \begin{cases}
    1&\text{if $i=j$,}\\
    0&\text{otherwise},
  \end{cases}
\]
and there exist (not necessarily distinct) $\lambda_1,\dots,\lambda_p\in\R$
such that
\[
Au_i=\lambda_iu_i
\]
for $i=1,\dots,p$.
\smallskip

{\bf Proof.} Linear algebra.
\hfill$\Box$
\medskip

{\bf Corollary.} Let~$A$ be the adjacency matrix for~$G$ with (not necessarily
distinct) eigenvalues~$\lambda_1,\dots,\lambda_p$.  Then the number of walks of
length~$\ell$ from~$v_i$ to~$v_j$ is
\[
  \sum_{k=1}^{p}u_{ik}u_{jk}\lambda_k^{\ell}
\]
where~$u_q:=(u_{1q},u_{2q},\ldots,u_{pq})$ for~$q=1,\ldots,p$.
\smallskip

{\bf Proof.} With notation as in the Theorem, let~$U$ be the $p\times p$ matrix
whose columns are the~$u_i$.  Then~$U^tU=I_p$, so~$U^{-1}=U^t$, and
\[
  \begin{tikzpicture}
    \node at (0,0) {$\displaystyle
    U^{-1}AU=\diag(\lambda_1,\dots,\lambda_p)=
    \left(\begin{array}{ccc}
	\lambda_1&&\\
	&\ddots&\\
	&&\lambda_p
    \end{array} \right).
    $};
    \node at (2,-0.4) {$\displaystyle \text{\large 0} $};
    \node at (3,0.4) {$\displaystyle \text{\large 0} $};
  \end{tikzpicture}
\]
Hence, 
\[
  (U^{-1}AU)^{\ell}=(U^{-1}AU)(U^{-1}AU)\cdots(U^{-1}AU)=U^{-1}A^{\ell}U,
\]
but also
\[
  (U^{-1}AU)^{\ell}=\diag(\lambda_1,\dots,\lambda_p)^{\ell}=
  \diag(\lambda_1^{\ell},\dots,\lambda_p^{\ell}).
\]
Letting~$D=(d_{st})=\diag(\lambda_1^{\ell},\dots,\lambda_p^{\ell})$, 
it follows that $A^{\ell}=UD^{\ell}U^{-1}$.  Therefore,
\begin{align*}
  (A^{\ell})_{ij}&=\sum_{k=1}^{p}u_{ik}(D^{\ell}U^{-1})_{kj}\\
  &=\sum_{k=1}^{p}u_{ik}(D^{\ell}U^t)_{kj}\\
  &= \sum_{k=1}^{p}u_{ik}\left( \sum_{s=1}^{p}(D^{\ell})_{ks}u_{js}\right)\\
  &= \sum_{k=1}^{^p}u_{ik}\lambda_k^{\ell}u_{jk}.
\end{align*}
\hfill$\Box$

{\bf Corollary.} The number of closed walks of length~$\ell$ in~$G$, i.e., the
number of walks of length~$\ell$ beginning and ending at the same vertex,
is~$\sum_{k=1}^{p}\lambda_k^{\ell}$.
\smallskip

{\bf Proof.} From our Proposition, the number of closed walks of length~$\ell$
is the sum of the diagonal entries of~$A^{\ell}$, i.e.,~$\trace(A^{\ell})$, the
{\em trace} of~$A^{\ell}$.  By a standard theorem from linear algebra, the trace
of a square matrix is the sum of its eigenvalues. 
Now note that
\[
  A^{\ell}u_i=A^{\ell-1}\left( \lambda_iu \right)=\lambda_i
  A^{\ell-1}u_i=\cdots=\lambda_i^{\ell}u_i
\]
for~$i=1,\dots,p$.  So the eigenvalues for~$A^{\ell}$ are~$\lambda_i^{\ell}$ for
$i=1,\dots,p$.  The result follows.
\hfill$\Box$ 
\medskip

{\bf Example.} Letting~$G=C_4$ be the cycle graph from the first example, we
have
\[
A=
\left(\begin{array}{cccc}
    0&1&0&1\\
    1&0&1&0\\
    0&1&0&1\\
    1&0&1&0
\end{array} \right).
\]
The eigenvalues for~$A$, with multiplicities, are $0,0,2,-2$.  So the number of
closed walks of length~$\ell$ for this cycle graph is
\[
  0^{\ell}+0^{\ell}+2^{\ell}+(-2)^{\ell}.
\]
Note that~$(0)^0=1$.
\end{document}


