
\documentclass{article}

\usepackage{xspace,graphicx,hyperref,paralist}

\newtheorem{illustration}{Illustration}[section]
\newtheorem{theorem}{Theorem}[section]


\newcounter{exer}
\renewcommand{\theexer}{\thechapter:\arabic{exer}}

\newcommand{\FIXIT}[1]{\typeout #1 -- {\LARGE\sf #1}}

%---
\newcommand{\TM}{{Turing machine}\xspace}
\newcommand{\TMs}{{Turing machines}\xspace}
\newcommand{\NPCness}{{NP-completeness}\xspace}
\newcommand{\NPC}{{NP-complete}\xspace}
\newcommand{\NPH}{{NP-hard}\xspace}
\newcommand{\sfP}{{\sf P}\xspace}
\newcommand{\sfNP}{{\sf NP}\xspace}
\newcommand{\sfNPC}{{\sf NPC}\xspace}
\newcommand{\sfNPH}{{\sf NPH}\xspace}
\newcommand{\sfCoNP}{{\sf CoNP}\xspace}
\newcommand{\sfCoNPC}{{\sf CoNPC}\xspace}
\newcommand{\BA}{{B\"{u}chi automata}\xspace}
\newcommand{\BAon}{{B\"{u}chi automaton}\xspace}
\newcommand{\TL}{{Temporal Logic}\xspace}
\newcommand{\LTL}{{linear-time temporal logic}\xspace}
\newcommand{\CTL}{{Computational Tree Logic}\xspace}
\newcommand{\KS}{{Kripke structure}\xspace}
\newcommand{\KSs}{{Kripke structures}\xspace}
\newcommand{\OR}{{$\omega$-regular}\xspace}
%---


\oddsidemargin 0cm
\textwidth 17cm

\begin{document}
{\hfill \large\bf CS 3100 -- Models of Computation -- Fall 2011 --  Practice Midterm-2 \hfill}

\vspace{1ex}

\begin{compactitem}
\item These questions will help toward MT2 (which will be shorter than
 this practice list).
\item In all questions, {\bf @ } or $\varepsilon$ mean ``epsilon,'' the empty string.
\item NFA states beginning with {\tt I}: initial states; beginning with {\tt F}: accepting states;
  beginning with {\tt IF}: both.
\item Anything such as {\tt 0, 1, 2, \#, a, b} will be considered to be terminals (members of $\Sigma$)
\item You are responsible for reading through the notes, especially the notions of acceptance of various
  machine types, as covered in notes22.pdf
\item While all regular languages are context-free, when we say ``context-free'' in a general setting,
  it always means ``context-free and not regular.'' This is similar
  to calling $0$ a complex number; makes no sense, 
even though $0 = 0.0 + i0.0$, a perfectly fine complex number.
\end{compactitem}
 

\begin{enumerate}

\item Is this a purely left-linear or purely right-linear grammar?

\begin{verbatim}
S -> a T 
T -> S b
S -> @
\end{verbatim}

\item How about this one? What class (regular or context-free)
\begin{verbatim}
T -> c T u | @
\end{verbatim}

\item Is this linear? What NFA does it denote?
\begin{verbatim}
T -> c T | d U | @
U -> a T
\end{verbatim}

\item[] Answer: Yes, it denotes the NFA
\begin{verbatim}
IFT - c -> IFT
IFT - d -> U
U - a -> IFT
\end{verbatim}

\item Convert this NFA to a left-linear grammar or a right-linear grammar:
\begin{verbatim}
I - 0 -> F1
F1 - 1 -> F1
F1 - 0 -> I
\end{verbatim}

\item[] Answer: The CFG is
\begin{verbatim}
I -> 0 F1
F1 -> @
F1 -> 1 F1
F1 -> 0 I
\end{verbatim}

\item Know how to reverse a CFG: Reverse

\begin{verbatim}
S -> a T 
T -> S b
S -> @ 
S -> U | V
U -> S a T b U
V -> S
\end{verbatim}

\item[] Answer: Reversed CFG is

\begin{verbatim}
S_r -> T_r a 
T_r -> b S_r
S_r -> @ 
S_r -> U_r | V_r
U_r -> U_r b T_r a S_r
V_r -> S_r
\end{verbatim}

\item Simplifying CFGs

\begin{verbatim}
S -> a T 
T -> S b
S -> @ 
S -> U | V
U -> S a T b U
V -> S
\end{verbatim}

\item[] The simplified CFG is:
\begin{verbatim}
S -> a T 
T -> S b  -- 3: T is generating
S -> @    -- 1: generating
S -> U | V 
U -> S a T b U -- 4: U is not generating
               -- U is not reachable
V -> S   -- 2: V is generating


S -> a T - keep
T -> S b - keep
S -> @   - keep
S -> V   - keep
U -> S a T b U - remove
V -> S - keep

Finally, 
S -> a S b
S -> @  

\end{verbatim}


\item Get the Pumping Lemma facts straight

\item[] Incorrect Proof:

In the PL proof for $\{ a^i b^j c^k \;\mid\; if\; even(i)\; then\; j=k \}$,
given an m-state DFA, someone picks the string
$a^3 b^m c^{m+1}$ and pumps. 
They pick $y$ = ``a'' and show that by pumping, we can make ``a'' part
even, and then b and c don't match. What is wrong?

\item[] Answer: Have to consider {\em all possible splits of the first m positions 
into x, y, z}. In our PL version (same as the one used in the JFLAP tutor), the $xyz$
string begins at the beginning of the string---not in the ``middle'' like another
PL version in my book allows.

\item[] Corrected Proof:
Even if you pick $a^{2m+1} b^m c^{m+1}$, you don't win, because
you don't know where the pump lies within $a$ and how long it is.

\item Easier Proof:

Reverse the language to obtain

$\{ c^k b^j a^i \;\mid\; if\; even(i)\; then\; j=k \}$

then pick $c^m b^m a^2$ which is in the language;
then pump ``c''.
No case analysis needed - only one case.. the string goes outside in one pump, regardless of what ``$y$'' (consisting only of ``c''s) is.

\item[] Let's say we pump up and obtain
$c^n b^m a^2$  where $n > m$ . Goes outside. So can't be regular.

\item Be able to design simple PDAs and CFGs

Design a PDA for the language 

\[ \{a^i b^j \;\mid\; i = j\; or\; i = 2j \} \]

\item[] Push the a's. When the b's come, for each b pop 2 a's.

\item Write a CFG for $\{a^i b^j \;\mid\; i = j \; or\; i = 2j \}$

\begin{verbatim}
S -> M | D

M -> a M b | @

D -> a a D b | @
\end{verbatim}

\item Converting CFG to PDA (not the other way)
Standard conversion.

\item Consistency and completeness of 
CFGs with respect to a language

given

\[ L = \{ a^i b^{2i} \;\mid\; i\ge 0 \}, \]

show that the grammar

\begin{verbatim}
 S -> a S bb | @
\end{verbatim}

is consistent and complete.
\item[] Answer: Consistency is easy (always double the number of b's). Completeness:
  If you assume, any such string of length $n$ generated from this CFG, the next
  longer string has one more a to the left and two more b's to the right; so one more
  derivation steps gets it!

\item Ambiguity, inherent ambiguity. 

Is this grammar ambiguous?

\begin{verbatim}
  S -> if E then X else X | if E then X
  E -> q
  X -> p
\end{verbatim}

Is this grammar ambiguous?

\begin{verbatim}
  S ->  M | U
  M -> if E then M else M | O
  U ->  if E then STMT
      | if E then M else U
  O -> p
  E -> q
\end{verbatim}
What is the language of this grammar?
Is the language of this grammar {\em inherently ambiguous}?

\item Show one use of this rule:
{\tt S -> if E then M else U}

i.e. an actual if-then-else stmt. Draw a parse tree.

\item[] Ans: {\tt if q then if q then p else p else if q then p}

\item Be able to design simple Turing machines.
Thoroughly study the \verb|w#w| DTM and the \verb|ww| NDTM. I'll ask variations in the exam.
I may also ask you to step them for simple inputs.

\item Also read the basic sections on TMs -- when they accept! What 'looping' means. 

\item Closure results and how to use them correctly. 

\item The {\em family} of regular languages is properly contained in the {\em family} of CFLs. This
  is a different idea from a {\em particular} CFL which always has a regular sub-language and
  a regular super-language.

\item Show that
CFLs are closed under union, concatenation, and starring .

\item[] Ans: Doing star is easy because we can use \verb|U -> S U | @ | (this stars the language of S).

\item Be able to classify languages in the PL tutor as being regular or context-free or non context-free.

\item Know about the Chomsky Hierarchy (notes19).

\item Know where non-determinism makes a difference (for which machines).

\end{enumerate}

\end{document}