\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{relsize}
\usepackage{algorithm2e}
\usepackage{mathrsfs}
\usepackage{tikz}
\usepackage{tkz-tab}
\usepackage[colorlinks,allcolors=blue]{hyperref} 
\newcounter{lecnum}
\usepackage{graphicx}
\graphicspath{./}
\usepackage{caption}
\usepackage{subcaption}
\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\lecture}[4]{
   \newpage
   \setcounter{lecnum}{#1}
   \noindent

   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 16cm { {\bf CS761 Derandomization and Pseudorandomness
                        \hfill 2022-23 Sem I} }
       \vspace{4mm}
       \hbox to 16cm { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 16cm { {\it Scribe: #4  \hfill  Lecturer: #3} }
      \vspace{2mm}}
   }
   \end{center}
   \vspace*{4mm}
}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}

\theoremstyle{definition}
\newtheorem{example}{Example}
\newtheorem{problem}{Problem}
\newtheorem{observation}{Observation}


\begin{document}

\lecture{9}{29-08-2022}{Rohit Gurjar}{Aniruddha Joshi}

\section{Magical Graphs and Codes}
In the last lecture we saw the definition and existence of \textbf{magical graphs}. 
We will show  how good error correcting codes can be constructed using such magical graphs. 

\begin{definition} A bipartite graph $(L,R,E)$ is a $(n,m,d)$-magical graph if the following holds
	\begin{itemize}
		\item $|L| = n$
		\item $|R| = m$
		\item $m\geq \frac{3n}{4}$
		\item $\forall v\in L~deg(v)=d$
		\item $\forall S \subseteq L,  |S|\leq \frac{n}{10d} \implies |\Gamma(S)| \geq \frac{5d|S|}{8}$
	\end{itemize}
\end{definition}

\begin{claim}\label{uniq_claim}
	For any $S\subseteq L$ such that $|S|\leq \frac{n}{10d}$, there exists a vertex $v\in \Gamma(S)$ such that $v$ has exactly one neighbour in $S$.
\end{claim}
\begin{proof}
	We prove this by contradiction.
	Since $\Gamma(S)$ is the set of neighbours of $S$, every vertex $v\in \Gamma(S)$ has at least one neigbour in $S$.
	Suppose every vertex $v$ has at least two neighbours in $S$, then $E(\Gamma(S), S)\geq 2|\Gamma(S)|$ and so $E(\Gamma(S), S)\geq \frac{10d|S|}{8}$, which is a contradiction as $E(\Gamma(S),S) = d|S|$ (because every vertex in $S$ has degree $d$).
\end{proof}

Now we will look at a construction of an error correcting code.

\begin{definition}[Linear Codes]
A code $\mathscr{C}\subseteq\{0,1\}^n$ can be viewed as $\mathscr{C}\subseteq\mathbb{F}_2^n$. $\mathscr{C}$ is called a linear code if $\forall x,y\in \mathbb{F}_2^n, (x\in \mathscr{C} \land y\in \mathscr{C}) \implies x+y\in \mathscr{C}$. Note that the $+$ operation is in the field $\mathbb{F}_2$.
\end{definition}

Let's consider a $(n,m,d)$-magical graph, such that $m=\frac{3n}{4}$ (in the last class we saw that such a graph exists).

\begin{definition}
We define a matrix $M \in \mathbb{R}^{m\times n}$ as follows:
$$M_{ij} = 1 \text{ iff } i\in R \text{ and } j\in L \text{ are adjacent}.$$
\end{definition}

\begin{definition}\label{def_lc}
Let us define a code as $\mathscr{C} = \{x: Mx=0\}$. (Note that the matrix multiplication is over $\mathbb{F}_2$)
The matrix $M$ in the above definition is called a parity check matrix.
\end{definition}

\begin{example}
Let $M=[1,1,1]$, the code $\mathscr{C}$ such that $\mathscr{C} = \{x: Mx=0\}$ is then given as $\mathscr{C}=\{(1,1,0),(1,0,1),(0,1,1),(0,0,0)\}$. Here $d_H({\mathscr{C}})=2$ and $r(\mathscr{C}) = \frac{2}{3}$.
\end{example}

From definition~\ref{def_lc}, we can see that $|\mathscr{C}|=2^{n-rank(M)}$ (because $n-rank(M)$ is the dimension of null space and power of 2 because it is in field $\mathbb{F}_2$).
So, $r(\mathscr{C})=\frac{n-rank(M)}{n}\geq \frac{1}{4}$ %(since $rank(M)\leq m$ and $m\geq \frac{3n}{4}$)

\begin{claim}
$d_H(\mathscr{C}) > \frac{n}{10d}$
\end{claim}
\begin{proof}
	Since $d_H(x,y)=\alpha \implies d_H(x-y,0)=\alpha$. Hence, $d_H(\mathscr{C})$ is nothing but the minimum weight (number of nonzero entries)
	in any codeword other than $0^n$.
	%we can just focus on non-zero entries of any code word.
	For the sake of contradiction, suppose $Z$ is a (nonzero) codeword with $\frac{n}{10d}$ non-zero entries, then let's define $S = \{v \in L : Z_v = 1\}$, that is $S$ is the set of all columns of $M$ such that their indices have non-zeros entries in $Z$. Notice that $MZ$ is just the sum of all the column vectors corresponding to $S$. So, by claim~\ref{uniq_claim} there exists a row $i$ such that there is exactly one vector in $S$ which has entry 1 in row $i$, so $MZ\neq 0$. That means, $Z$ is not a codeword, which is  a contradiction.
\end{proof}



\section{Undirected Connectivity}
\begin{problem} Given a graph $G$, and two vertices $s,t\in G$, is there a path between $s$ and $t$? (we are looking for a $\log$-space algorithm)
\end{problem}
Let us look at an algorithm.

$\mathbf{IsPath(s, t, 2^\ell)}$ outputs whether there is a path between $s$ and $t$ with length at most $2^l$.

\textbf{Algorithm} %\vspace{-0.3cm}
\begin{algorithm}{$IsPath(s, t, 2^\ell)$\{}

\eIf{$(s,t)\in E$}
{
    return YES\;
}{
    \For{$v\in V$}{
		\If{$IsPath(s,v,2^{\ell-1})==$YES and $IsPath(v,t,2^{\ell-1})==$YES}
		{
		    return YES\;
		}	
    }
    return NO\;
}\}

\caption{Function IsPath}
\label{alg1}
\end{algorithm}

We can see that algorithm~\ref{alg1} works in $O(\log n \times \log n)$ space. 
We can see this as follows, the maximum depth of the algorithm is 
$O(\ell)=O(\log n) $ and in each instance, we need $O(\log n)$ space to store the number corresponding to $v$, $s$, $t$ and $\ell$.
Also, note that the algorithm is not polynomial time. 

Now we will see a randomized algorithm for the same problem with $O(\log n)$ space.

\textbf{Algorithm}
\begin{enumerate}
\item $v\leftarrow s$
\item $u \leftarrow$  a neighbour of $v$ chosen uniformly randomly
\item if $u==t$ return YES
\item otherwise $v\leftarrow u$, go to 1.
\end{enumerate}

\begin{claim}
$\Pr\left[\text{t is seen within } O(n^3 \log n) \text{ steps} \right] \geq \frac{1}{2}$ 
\end{claim}
We will see the proof of this claim in the next class. 

\textbf{Side note}: This algorithm will not work for directed graphs (i.e in $O(n^3 logn)$ steps.  There may be an exponentially small probability to reach $t$ from $s$. Counter-example: consider a family of graphs $G_n$ such that the vertices are $V = \{1,2,\cdots,n\}\cup\{s,t\}$ and the edges are $E = \{(i,i+1)| i<n\}\cup \{(i,s)|\forall i\} \cup \{(s,1),(n,t)\}$.

\vspace{0.3cm}
We will only consider undirected graphs for this algorithm.

For simplicity let us assume that the given graph is $d$-regular (if the graph is not $d$-regular then add self loops).

\begin{definition}
Let us define a random walk matrix $M$ such that
 $$M_{ij} = \frac{\delta_{ij}}{d},\text{ where }\delta_{ij}\text{ is the number of edges between vertex }i \text{ and vertex j}$$
\end{definition}
\newpage

We define a probability vector $v^{(t)} \in \mathbb{R}^n$ such that $v^{(t)}_i$ is the probability of reaching at vertex $i$ at  time $t$. 
Clearly, for all $i$, $0 \leq v^{(t})_i \leq 1$ and
$\sum\limits_{i} v^{(t)}_i = 1$.
Observe that 
 $$v^{(t+1)} = Mv^{(t)}.$$
 If our walk starts at $s$ then $v^{(0)}_s = 1$ and for $i\neq s$, $v^{(0)}_i = 0$.

So it is easy to see that $v^{(t)} = M^t v^{(0)}$ (does $v^{(t)}$ converge to a probability distribution?)
\begin{observation}
 If $u = (\frac{1}{n},\frac{1}{n},\cdots,\frac{1}{n})$, then $Mu=u$
\end{observation}
Are there any other stationary distributions?

If $G$ is not connected then there can be several stationary distributions.
	\begin{figure}[h!]
		\hspace{5cm}
        \begin{tikzpicture}
            %% vertices
            \draw[fill=black] (0,0) circle (3pt);
            \draw[fill=black] (1,0) circle (3pt);
            \draw[fill=black] (0.5,1) circle (3pt);
            \draw[fill=black] (2,0) circle (3pt);
            \draw[fill=black] (2,1) circle (3pt);
            
            %% vertex labels
            \node at (-0.25,0) {$\frac{1}{3}$};
            \node at (0.75,1) {$\frac{1}{3}$};
            \node at (1.25,0) {$\frac{1}{3}$};
            \node at (2.25,0) {$0$};
            \node at (2.25,1) {$0$};
            
            %%% edges
            \draw (0,0) -- (1,0);
            \draw (1,0) -- (0.5,1);
            \draw (0.5,1) -- (0,0);
            \draw (2,1) -- (2,0);
            
        \end{tikzpicture}
    \caption{Graph with non-uniform stationary distribution}
	\end{figure}

\end{document}
