%This is a comment
%This is a sample LaTeX file you may use to produce homework solutions

\documentclass[11pt]{article} %11pt is the font size
                              %You may also use 12pt for a larger print
\usepackage{exscale}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage{times,mathptm}
\usepackage{epsfig}

\textwidth 6.5truein          %The next four commands define the page size
\textheight 9.0truein
\oddsidemargin 0.0in
\topmargin -0.6in

\parindent 0pt             %No indentation at the start of each paragraph
\parskip 5pt               %5pt is the gap between paragraphs
\def\baselinestretch{1.1}  %The larger the number, the more space between lines

\begin{document}

\title{CSci 423/523 Homework 1}
\author{Your name}
\date{Today's date}
\maketitle

{\bf PROBLEM 1.} Prove that any nonempty tree has one more nodes than 
it has edges.

{\bf PROOF.}
We prove by structual induction that for a nonempty tree $T$ with $n$
nodes and $e$ edges, $n = e + 1$.

{\bf Basis:} The basis case is $n = 1$. Obviously, a tree with
only one node does not have any edges, suggesting $e = 0$. So $n = e + 1$.

{\bf Induction:} We assume that for any tree with less than $n$
nodes the equality holds true. Now onsider a tree $T$ with $n$ nodes. 
Assume that $T$ contains $k$ subtrees, $T_1, T_2, \ldots, T_k$ and that 
subtree $T_i$, for $i = 1, 2, \ldots, k$, has $n_i$ nodes and $e_i$ edges.
Notice that $e = \sum_{i=1}^k e_i + k$.
Since $n_i < n $, then by the induction hypothesis $n_i = e_i + 1$ for
all $i$'s. Therefore,
\begin{eqnarray*}
n &=& \sum_{i=1}^k n_i + 1\\
  &=& \sum_{i=1}^k (e_i + 1) +1\\
  &=& \sum_{i=1}^k e_i + k + 1\\
  &=& e + 1.
\end{eqnarray*}

This completes the induction.

{\bf PROBLEM 2.} Construct an NFA accepting all strings over alphabet 
$\{0,1\}$ with a substring of $01$.

{\bf SOLUTION:} Let NFA $N = (Q, \Sigma, \delta, q_0, F)$ be the NFA
that accepts the language, where 
\begin{itemize}
\item $Q = \{q_0, q_1, q_2\}$;
\item $\Sigma = \{0, 1\}$;
\item $q_0$ is the start state;
\item $F = \{q_2\}$; and
\item $\delta: Q \times \Sigma \rightarrow 2^Q$ contains the following
transitions:
\begin{center}
\begin{tabular}{r||l|l}
                  & $0$           & $1$       \\\hline\hline
$\rightarrow q_0$ & $\{q_0,q_1\}$ & $\{q_0\}$ \\
$q_1$             & $\emptyset$   & $\{q_2\}$ \\
$*q_2$             & $\{q_2\}$     & $\{q_2\}$
\end{tabular}
\end{center}

\end{itemize}

We also give the transition diagram for the NFA in Figure 1.

\vskip 0.4cm
\centerline{\epsfig{figure=nfa.eps,height=0.7in,width=3in}}
\centerline{Figure 1. An NFA that accepts all strings with substring $01$.}
\vskip 0.4cm

%This is another way to include a figure if you are using TexShop on Mac
%\begin{figure}
%\begin{center}
%\includegraphics[height=0.7in,width=3in]{nfa.pdf}
%\caption{An NFA that accepts all strings with substring $01$.}
%\end{center}
%\end{figure}


\end{document}
