Added first part of DFA handout
This commit is contained in:
parent
36a70306d1
commit
e3fd62c791
@ -1,13 +1,10 @@
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
\documentclass[
|
||||
solutions,
|
||||
%shortwarning
|
||||
solutions
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\include{tikxset.tex}
|
||||
|
||||
\tikzset{loop above/.style={min distance=5mm,looseness=10}}
|
||||
\input{tikxset.tex}
|
||||
|
||||
\begin{document}
|
||||
|
||||
@ -19,7 +16,6 @@
|
||||
|
||||
|
||||
\input{parts/0 DFA.tex}
|
||||
|
||||
|
||||
%\input{parts/1 regular.tex}
|
||||
|
||||
\end{document}
|
@ -13,9 +13,11 @@ Consider the automaton $A$ shown below:
|
||||
\node[main] (a) at (0, 0) {$a$};
|
||||
\node[accept] (b) at (2, 0) {$b$};
|
||||
\node[main] (c) at (5, 0) {$c$};
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(s) edge (a)
|
||||
(a) edge node[label] {$1$} (b)
|
||||
(a) edge[loop above] node[label] {$0$} (a)
|
||||
(b) edge[bend left] node[label] {$0$} (c)
|
||||
@ -25,12 +27,17 @@ Consider the automaton $A$ shown below:
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
$A$ always starts in the state $q_1$. This is called the \textit{start state}. \par
|
||||
It takes strings using letters in the alphabet $\{0, 1\}$ and reads them left to right, moving between states along the edges marked by each letter.
|
||||
$A$ takes strings of letters in the alphabet $\{0, 1\}$ and reads them left to right, one letter at a time. \par
|
||||
Starting in the state $a$, the automaton $A$ will move between states along the edge marked by each letter. \par
|
||||
|
||||
For example, consider the string \texttt{1011}. Processing this string, $A$ will go through the states $q_1 - q_2 - q_3 - q_2 - q_2$. \par
|
||||
Note that $q_2$ has a circle in the diagram above. This means that the state $q_2$ is \textit{accepting}, and that all the strings which end up in it are \textit{accepted}. Similarly, states $q_1$ and $q_3$ are \textit{rejecting} and the strings which end up there are \textit{rejected}.
|
||||
\vspace{2mm}
|
||||
|
||||
Note that node $b$ has a \say{double edge} in the diagram above. This means that the state $b$ is \textit{accepting}. Any string that makes $A$ end in state $b$ is \textit{accepted}. Similarly, strings that end in states $a$ or $c$ are \textit{rejected}. \par
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
For example, consider the string \texttt{1011}. \par
|
||||
$A$ will go through the states $a - b - c - b - b$ while processing this string. \par
|
||||
|
||||
|
||||
\problem{}
|
||||
@ -47,7 +54,7 @@ Which of the following strings are accepted by $A$? \\
|
||||
|
||||
|
||||
\problem{}
|
||||
Describe the general form of a string accepted by $A$.
|
||||
Describe the general form of a string accepted by $A$. \par
|
||||
\hint{Work backwards from the accepting state, and decide what all the strings must look like at the end in order to be accepted.}
|
||||
|
||||
\begin{solution}
|
||||
@ -70,9 +77,13 @@ It starts in the state $s$ and has two accepting states $a_1$ and $b_1$.
|
||||
\node[main] (a2) at (-2, -2.5) {$a_2$};
|
||||
\node[accept] (b1) at (2, -0.5) {$b_1$};
|
||||
\node[main] (b2) at (2, -2.5) {$b_2$};
|
||||
\node[start] (start) at (0, 1) {\texttt{start}};
|
||||
\end{scope}
|
||||
|
||||
\clip (-4, -3.5) rectangle (4, 1);
|
||||
|
||||
\draw[->]
|
||||
(start) edge (s)
|
||||
(s) edge node[label] {\texttt{a}} (a1)
|
||||
(a1) edge[loop left] node[label] {\texttt{a}} (a1)
|
||||
(a1) edge[bend left] node[label] {\texttt{b}} (a2)
|
||||
@ -87,9 +98,6 @@ It starts in the state $s$ and has two accepting states $a_1$ and $b_1$.
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
|
||||
|
||||
|
||||
\problem{}
|
||||
Which of the following strings are accepted by $B$:
|
||||
\begin{itemize}
|
||||
@ -107,7 +115,7 @@ Which of the following strings are accepted by $B$:
|
||||
Describe the strings accepted by $B$.
|
||||
|
||||
\begin{solution}
|
||||
They are strings that start and end with the same letter.
|
||||
$B$ accepts strings that start and end with the same letter.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
@ -135,7 +143,7 @@ A \textit{language} over an alphabet $Q$ is a subset of $Q^*$. \\
|
||||
For example, the language \say{strings of length 2} over $\{\texttt{0}, \texttt{1}\}$ is $\{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$
|
||||
|
||||
\definition{}
|
||||
We say a language $L$ is \textit{recognized} by a DFA $A$ if that DFA accepts a string $w$ iff $w \in L$.
|
||||
We say a language $L$ is \textit{recognized} by a DFA if that DFA accepts a string $w$ if and only if $w \in L$.
|
||||
|
||||
|
||||
%\begin{remark}
|
||||
@ -154,20 +162,23 @@ How many strings of length $n$ are accepted by the automaton $C$?
|
||||
\node[main] (0) at (0, 0) {$0$};
|
||||
\node[accept] (1) at (3, 0) {$1$};
|
||||
\node[main] (2) at (5, 0) {$2$};
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(a) edge[loop above] node[label] {\texttt{b}} (a)
|
||||
(a) edge[bend left] node[label] {\texttt{a}} (b)
|
||||
(b) edge[bend left] node[label] {\texttt{b}} (a)
|
||||
(b) edge node[label] {\texttt{a}} (c)
|
||||
(c) edge[loop above] node[label] {\texttt{a, b}} (c)
|
||||
(s) edge (0)
|
||||
(0) edge[loop above] node[label] {\texttt{b}} (0)
|
||||
(0) edge[bend left] node[label] {\texttt{a}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{b}} (0)
|
||||
(1) edge node[label] {\texttt{a}} (2)
|
||||
(2) edge[loop above] node[label] {\texttt{a,b}} (2)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\begin{solution}
|
||||
If $A_n$ is the number of accepted strings of length $n$, then $A_n = A_{n-1}+A_{n-2}$. Together with initial conditions, we see that $A_n$ is an $n+2$-th Fibonacci number.
|
||||
If $A_n$ is the number of accepted strings of length $n$, then $A_n = A_{n-1}+A_{n-2}$. \par
|
||||
Computing initial conditions, we see that $A_n$ is an $n+2$-th Fibonacci number.
|
||||
\end{solution}
|
||||
|
||||
%\begin{remark}
|
||||
@ -178,7 +189,7 @@ How many strings of length $n$ are accepted by the automaton $C$?
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
Draw DFAs that recognize the following languages. In all parts, the alphabet is $\{0,1\}$:
|
||||
Draw DFAs that recognize the following languages. In all parts, the alphabet is $\{0, 1\}$:
|
||||
\begin{itemize}
|
||||
\item $\{w~ | ~w~ \text{begins with a \texttt{1} and ends with a \texttt{0}}\}$
|
||||
\item $\{w~ | ~w~ \text{contains at least three \texttt{1}s}\}$
|
||||
@ -188,82 +199,440 @@ Draw DFAs that recognize the following languages. In all parts, the alphabet is
|
||||
\item $\{w~ | ~w~ \text{doesn't contain the substring \texttt{110}}\}$
|
||||
\end{itemize}
|
||||
|
||||
|
||||
\begin{solution}
|
||||
%\part{a} \includegraphics[width=0.3\linewidth]{6a.png}
|
||||
%\part{b} \includegraphics[width=0.4\linewidth]{6b.png}
|
||||
%\part{c} \includegraphics[width=0.3\linewidth]{6c.png}
|
||||
$\{w~ | ~w~ \text{begins with a \texttt{1} and ends with a \texttt{0}}\}$
|
||||
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[accept] (0) at (0, 2) {$\phantom{0}$};
|
||||
\node[main] (1) at (3, 2) {$\phantom{0}$};
|
||||
\node[main] (2) at (0, 0) {$\phantom{0}$};
|
||||
\node[main] (3) at (3, 0) {$\phantom{0}$};
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\end{scope}
|
||||
|
||||
\clip (-2, -1) rectangle (4.5, 3);
|
||||
|
||||
\draw[->]
|
||||
(s) edge (2)
|
||||
(0) edge[loop left] node[label] {\texttt{1}} (0)
|
||||
(0) edge[bend left] node[label] {\texttt{1}} (1)
|
||||
(1) edge[loop right] node[label] {\texttt{1}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{0}} (0)
|
||||
(2) edge[out=90, in=270] node[label] {\texttt{1}} (1)
|
||||
(2) edge node[label] {\texttt{0}} (3)
|
||||
(3) edge[loop right] node[label] {\texttt{1,0}} (3)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
$\{w~ | ~w~ \text{contains at least three \texttt{1}s}\}$
|
||||
|
||||
\begin{center}
|
||||
|
||||
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[main] (1) at (2, 0) {$\phantom{0}$};
|
||||
\node[main] (2) at (4, 0) {$\phantom{0}$};
|
||||
\node[accept] (3) at (6, 0) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge[loop above] node[label] {\texttt{0}} (0)
|
||||
(1) edge[loop above] node[label] {\texttt{0}} (1)
|
||||
(2) edge[loop above] node[label] {\texttt{0}} (2)
|
||||
(3) edge[loop above] node[label] {\texttt{0,1}} (3)
|
||||
(0) edge node[label] {\texttt{1}} (1)
|
||||
(1) edge node[label] {\texttt{1}} (2)
|
||||
(2) edge node[label] {\texttt{1}} (3)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
$\{w~ | ~w~ \text{contains the substring \texttt{0101}}\}$
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[main] (1) at (2, 1) {$\phantom{0}$};
|
||||
\node[main] (2) at (4, 1) {$\phantom{0}$};
|
||||
\node[main] (3) at (0, 3) {$\phantom{0}$};
|
||||
\node[accept] (4) at (2, 3) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
% Tikz includes invisible handles in picture size.
|
||||
% This crops the image to fix sizing.
|
||||
\clip (-2, -1.75) rectangle (5, 5.25);
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge[loop above] node[label] {\texttt{1}} (0)
|
||||
(0) edge[bend right] node[label] {\texttt{0}} (1)
|
||||
(1) edge[loop above] node[label] {\texttt{0}} (1)
|
||||
(1) edge node[label] {\texttt{1}} (2)
|
||||
(3) edge[bend right] node[label] {\texttt{0}} (1)
|
||||
(3) edge node[label] {\texttt{1}} (4)
|
||||
(4) edge[loop above] node[label] {\texttt{0,1}} (4)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 10mm]
|
||||
(2) to (4, 5) to node[label] {\texttt{0}} (0, 5) to (3)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 10mm]
|
||||
(2) to (4, -1.5) to node[label] {\texttt{1}} (0, -1.5) to (0)
|
||||
;
|
||||
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\medskip
|
||||
Notice that after getting two 0's in a row we don't reset to the initial state.
|
||||
%\part{d} \includegraphics[width=0.4\linewidth]{6d.png}
|
||||
%\part{e} \includegraphics[width=0.3\linewidth]{6e.png}
|
||||
%\part{f} \includegraphics[width=0.4\linewidth]{6f.png}
|
||||
|
||||
\medskip
|
||||
\pagebreak
|
||||
$\{w~ | ~w~ \text{has length at least three and its third symbol is a \texttt{0}}\}$
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[main] (1) at (2, 0) {$\phantom{0}$};
|
||||
\node[main] (2) at (4, 0) {$\phantom{0}$};
|
||||
\node[accept] (3) at (6, 1) {$\phantom{0}$};
|
||||
\node[accept] (4) at (6, -1) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\clip (-2, -2.5) rectangle (7, 2.5);
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge node[label] {\texttt{0,1}} (1)
|
||||
(1) edge node[label] {\texttt{0,1}} (2)
|
||||
(2) edge node[label] {\texttt{0}} (3)
|
||||
(2) edge node[label] {\texttt{1}} (4)
|
||||
(3) edge[loop above] node[label] {\texttt{0,1}} (3)
|
||||
(4) edge[loop below] node[label] {\texttt{0,1}} (4)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
$\{w~ | ~w~ \text{starts with \texttt{0} and has odd length, or starts with \texttt{1} and has even length}\}$
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (2, 1) {$\phantom{0}$};
|
||||
\node[main] (2) at (4, 1) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge node[label] {\texttt{0}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{0,1}} (2)
|
||||
(2) edge[bend left] node[label] {\texttt{0,1}} (1)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 5mm]
|
||||
(0) to node[label] {\texttt{1}} (4, 0) to (2)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
$\{w~ | ~w~ \text{doesn't contain the substring \texttt{110}}\}$
|
||||
|
||||
\begin{center}
|
||||
|
||||
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (s) at (-2, 0){\texttt{start}};
|
||||
\node[accept] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (2, 0) {$\phantom{0}$};
|
||||
\node[accept] (2) at (4, 0) {$\phantom{0}$};
|
||||
\node[main] (3) at (6, 0) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge[loop above] node[label] {\texttt{0}} (0)
|
||||
(2) edge[loop above] node[label] {\texttt{1}} (2)
|
||||
(3) edge[loop above] node[label] {\texttt{0,1}} (3)
|
||||
(0) edge[bend left] node[label] {\texttt{1}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{0}} (0)
|
||||
(1) edge node[label] {\texttt{1}} (2)
|
||||
(2) edge node[label] {\texttt{0}} (3)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
Notice that after getting three 1's in a row we don't reset to the initial state.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Draw a DFA over an alphabet $\{\texttt{a}, \texttt{b}, \texttt{@}, \texttt{.}\}$ recognizing the language of strings of the form \texttt{user@website.domain}, where \texttt{user}, \texttt{website} and \texttt{domain} are nonempty strings over $\{\texttt{a}, \texttt{b}\}$ and \texttt{domain} has length 2 or 3.
|
||||
|
||||
\begin{solution}
|
||||
%\includegraphics[width=0.9\linewidth]{Email.png}
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
Draw a state diagram for a DFA over an alphabet of your choice that recognizes exactly $f(n)$ strings of length $n$ if \\
|
||||
Draw a DFA over an alphabet $\{\texttt{a}, \texttt{b}, \texttt{@}, \texttt{.}\}$ recognizing the language of strings of the form \texttt{user@website.domain}, where \texttt{user}, \texttt{website} and \texttt{domain} are nonempty strings over $\{\texttt{a}, \texttt{b}\}$ and \texttt{domain} has length 2 or 3.
|
||||
|
||||
\begin{solution}
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (start) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[main] (1) at (0, 2) {$\phantom{0}$};
|
||||
\node[main] (2) at (0, 4) {$\phantom{0}$};
|
||||
\node[main] (3) at (0, 6) {$\phantom{0}$};
|
||||
\node[main] (4) at (0, 8) {$\phantom{0}$};
|
||||
\node[main] (5) at (0, 10) {$\phantom{0}$};
|
||||
\node[accept] (6) at (0, 12) {$\phantom{0}$};
|
||||
\node[accept] (7) at (0, 14) {$\phantom{0}$};
|
||||
|
||||
\node[main] (8) at (5, 7) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(start) edge (0)
|
||||
(0) edge node[label] {\texttt{a,b}} (1)
|
||||
(1) edge node[label] {\texttt{@}} (2)
|
||||
(2) edge node[label] {\texttt{a,b}} (3)
|
||||
(3) edge node[label] {\texttt{.}} (4)
|
||||
(4) edge node[label] {\texttt{a,b}} (5)
|
||||
(5) edge node[label] {\texttt{a,b}} (6)
|
||||
(6) edge node[label] {\texttt{a,b}} (7)
|
||||
|
||||
(1) edge[loop left] node[label] {\texttt{a,b}} (1)
|
||||
(3) edge[loop left] node[label] {\texttt{a,b}} (3)
|
||||
|
||||
(0) edge[out=0, in=270] node[label] {\texttt{@,.}} (8)
|
||||
(1) edge[out=0, in=245] node[label] {\texttt{.}} (8)
|
||||
(2) edge[out=0, in=220] node[label] {\texttt{@,.}} (8)
|
||||
(3) edge[out=0, in=195] node[label] {\texttt{@}} (8)
|
||||
(4) edge[out=0, in=170] node[label] {\texttt{@,.}} (8)
|
||||
(5) edge[out=0, in=145] node[label] {\texttt{@,.}} (8)
|
||||
(6) edge[out=0, in=120] node[label] {\texttt{@,.}} (8)
|
||||
(7) edge[out=0, in=95] node[label] {\texttt{a,b,@,.}} (8)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 5mm]
|
||||
(8) to +(1.5, 1) to node[label] {\texttt{a,b,@,.}} +(1.5, -1) to (8)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
Draw a state diagram for a DFA over an alphabet of your choice that accepts exactly $f(n)$ strings of length $n$ if \\
|
||||
\begin{itemize}
|
||||
\item $f(n) = n$
|
||||
\item $f(n) = n+1$
|
||||
\item $f(n) = 3^n$
|
||||
\item $f(n) = n^2$
|
||||
\item $f(n)$ is a Tribonacci number. \par
|
||||
\textit{Tribonacci numbers} are defined by the sequence $f(0) = 0$, $f(1) = 1$, $f(2) = 1$,
|
||||
Tribonacci numbers are defined by the sequence $f(0) = 0$, $f(1) = 1$, $f(2) = 1$,
|
||||
and $f(n) = f(n-1)+f(n-2)+f(n-3)$ for $n \ge 3$ \par
|
||||
\hint{Fibonacci numbers are given by the automaton prohibiting two \texttt{a}s in a row.}
|
||||
\hint{Fibonacci numbers are given by the automaton prohibiting two \texttt{'a'}s in a row.}
|
||||
\end{itemize}
|
||||
|
||||
|
||||
\begin{solution}
|
||||
\begin{itemize}
|
||||
\item You would need to have an alphabet with three letters.
|
||||
\item Consider the language of words over $\{0, 1, 2\}$ having the sum of digits equal to $2$, so they contain two 1's or one 2. %\includegraphics[width=0.5\linewidth]{NSqrd.png}
|
||||
\item Following the hint gives the automaton %\includegraphics[width=0.5\linewidth]{Trib1.png}
|
||||
\item For this automaton $f(n)$ gives Tribonacci numbers with a shift: $f(0)=1$, $f(1)=2$, $f(2)=4$, $f(3)=7$. To account for the shift one can move the starting state in, e.g., this fashion:
|
||||
%\includegraphics[width=0.5\linewidth]{Trib2.png}
|
||||
\end{itemize}
|
||||
|
||||
\textbf{Part 4:} $f(n) = n^2$ \par
|
||||
Consider the language of words over $\{0, 1, 2\}$ that have the sum of their digits equal to $2$. \par
|
||||
Such words must contain two ones or one two:
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (start) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (2, 0) {$\phantom{0}$};
|
||||
\node[main] (2) at (0, -2) {$\phantom{0}$};
|
||||
\node[main] (3) at (2, -2) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\clip (-2, 1.5) rectangle (4, -2.75);
|
||||
|
||||
\draw[->]
|
||||
(start) edge (0)
|
||||
|
||||
(0) edge[loop above] node[label] {\texttt{0}} (0)
|
||||
(1) edge[loop above] node[label] {\texttt{0}} (1)
|
||||
(2) edge[loop left] node[label] {\texttt{0}} (2)
|
||||
(3) edge[loop right] node[label] {\texttt{0,1,2}} (3)
|
||||
|
||||
(0) edge node[label] {\texttt{2}} (1)
|
||||
(0) edge node[label] {\texttt{1}} (2)
|
||||
(1) edge node[label] {\texttt{1,2}} (3)
|
||||
(2) edge node[label] {\texttt{1}} (1)
|
||||
(2) edge node[label] {\texttt{2}} (3)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
|
||||
|
||||
\textbf{Part 5:} Tribonacci numbers \par
|
||||
Using the hint, we get the following automaton. \par
|
||||
It rejects all strings with three \texttt{'a'}s in a row.
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (start) at (-2, 0) {\texttt{start}};
|
||||
\node[accept] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (0, 2) {$\phantom{0}$};
|
||||
\node[accept] (2) at (2, 0) {$\phantom{0}$};
|
||||
\node[main] (3) at (4, 0) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(start) edge (0)
|
||||
(0) edge[loop below] node[label] {\texttt{b}} (0)
|
||||
(3) edge[loop above] node[label] {\texttt{a,b}} (3)
|
||||
(0) edge[bend left] node[label] {\texttt{a}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{b}} (0)
|
||||
(1) edge[bend left] node[label] {\texttt{a}} (2)
|
||||
(2) edge node[label] {\texttt{a}} (3)
|
||||
(2) edge node[label] {\texttt{b}} (0)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
This automaton rejects all strings with three \texttt{'a'}s in a row. If we count accepted strings, we get the Tribonacci numbers with an offest: $f(0) = 1$, $f(1) = 2$, $f(2)=4$, ... \par
|
||||
|
||||
\pagebreak
|
||||
|
||||
We can fix this by adding a node and changing the start state:
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (start) at (1, -2) {\texttt{start}};
|
||||
\node[accept] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (0, 2) {$\phantom{0}$};
|
||||
\node[accept] (2) at (2, 0) {$\phantom{0}$};
|
||||
\node[main] (3) at (4, 0) {$\phantom{0}$};
|
||||
\node[main] (4) at (3, -2) {$\phantom{0}$};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(start) edge (4)
|
||||
(2) edge node[label] {\texttt{b}} (0)
|
||||
(4) edge node[label] {\texttt{b}} (2)
|
||||
(4) edge node[label] {\texttt{a}} (3)
|
||||
|
||||
(0) edge[loop below] node[label] {\texttt{b}} (0)
|
||||
(3) edge[loop above] node[label] {\texttt{a,b}} (3)
|
||||
(0) edge[bend left] node[label] {\texttt{a}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{b}} (0)
|
||||
(1) edge[bend left] node[label] {\texttt{a}} (2)
|
||||
(2) edge node[label] {\texttt{a}} (3)
|
||||
(2) edge node[label] {\texttt{b}} (0)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
% \problem{}
|
||||
% Draw a DFA over an alphabet $\{a, b, c\}$, accepting all the suffixes of the string $abbc$ (including $\varepsilon$) and only them.
|
||||
%
|
||||
% \com{TD}{Something suffix automaton}
|
||||
|
||||
|
||||
\problem{}
|
||||
Draw a DFA recognizing the language of strings over $\{\texttt{0}, \texttt{1}\}$ in which \texttt{0} is the third digit from the end. \par
|
||||
Prove that any such DFA must have at least 8 states.
|
||||
|
||||
\begin{solution}
|
||||
\begin{solution}
|
||||
|
||||
\textbf{Part 1:} \par
|
||||
Index the states by triples of digits \texttt{000}, \texttt{001}, ..., \texttt{111}. All strings which end by 3 digits $d_1d_2d_3$ will end up in the state $d_1d_2d_3$. The starting state will be \texttt{111}. The transitions from $d_1d_2d_3$ by \texttt{0} and \texttt{1} will lead to $d_2d_3\texttt{0}$ and $d_2d_3\texttt{1}$, respectively. Accepting states are states with indices starting with \texttt{0}.
|
||||
Index the states by three-letter suffixes \texttt{000}, \texttt{001}, ..., \texttt{111}. All strings that end with letters $d_1d_2d_3$ will end up in the state $d_1d_2d_3$. We accept all states that start with a \texttt{0}. \par
|
||||
Note that we can start at any node if we ignore strings with fewer than three letters.
|
||||
|
||||
%\includegraphics[width=0.7\linewidth]{9.png}
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[start] (start) at (-2, 0) {\texttt{start}};
|
||||
\node[main] (7) at (0, 0) {\texttt{111}};
|
||||
\node[accept] (3) at (0, -2) {\texttt{011}};
|
||||
\node[main] (6) at (2, -2) {\texttt{110}};
|
||||
\node[main] (4) at (4, -2) {\texttt{100}};
|
||||
\node[accept] (1) at (-4, -4) {\texttt{001}};
|
||||
\node[main] (5) at (0, -4) {\texttt{101}};
|
||||
\node[accept] (2) at (-2, -4) {\texttt{010}};
|
||||
\node[accept] (0) at (-2, -6) {\texttt{000}};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(0) edge[loop left, looseness = 7] node[label] {\texttt{0}} (0)
|
||||
(7) edge[loop above, looseness = 7] node[label] {\texttt{1}} (7)
|
||||
|
||||
(start) edge (7)
|
||||
|
||||
(0) edge[out=90,in=-90] node[label] {\texttt{1}} (1)
|
||||
(1) edge node[label] {\texttt{0}} (2)
|
||||
(1) edge[out=45,in=-135] node[label] {\texttt{1}} (3)
|
||||
(2) edge[bend left] node[label] {\texttt{1}} (5)
|
||||
(3) edge node[label] {\texttt{0}} (6)
|
||||
(3) edge node[label] {\texttt{1}} (7)
|
||||
(5) edge[bend left] node[label] {\texttt{0}} (2)
|
||||
(5) edge node[label] {\texttt{1}} (3)
|
||||
(6) edge[bend left] node[label] {\texttt{0}} (4)
|
||||
(6) edge[out=-90,in=0] node[label] {\texttt{1}} (5)
|
||||
(7) edge[out=0,in=90] node[label] {\texttt{0}} (6)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 10mm]
|
||||
(4) to (4, 2) to node[label] {\texttt{1}} (-4, 2) to (1)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 10mm]
|
||||
(4) to (4, -6) to node[label] {\texttt{0}} (0)
|
||||
;
|
||||
|
||||
\draw[->, rounded corners = 5mm]
|
||||
(2) to (-2, -5) to node[label] {\texttt{0}} (3, -5) to (3, -2) to (4)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\linehack{}
|
||||
|
||||
\textbf{Part 2:} \par
|
||||
Strings \texttt{000}, \texttt{001}, ..., \texttt{111} should lead to pairwise different states since they differ in $i$-th position and after completing them with $i-1$ digit, they will need to be in different states.
|
||||
Strings \texttt{000}, \texttt{001}, ..., \texttt{111} must lead to pairwise different states. \par
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Assume \texttt{101} and \texttt{010} lead to the same state. Append a \texttt{1} to the end of the string. \par
|
||||
\texttt{101} will become \texttt{011}, and \texttt{010} will become \texttt{101}. These must be different states, since we accept \texttt{011} and reject \texttt{101}. We now have a contradiction: one edge cannot lead to two states!
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
\texttt{101} and \texttt{010} must thus correspond to distinct states. \par
|
||||
We can repeat this argument for any other pair of strings. \par
|
||||
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
@ -17,29 +17,63 @@
|
||||
execute at end scope={\endpgfonlayer}
|
||||
},
|
||||
%
|
||||
% Arrowhead tweaks
|
||||
% Arrowhead tweak
|
||||
>={Latex[ width=2mm, length=2mm ]},
|
||||
%
|
||||
% Labels inside edges
|
||||
label/.style = {
|
||||
circle,
|
||||
rectangle,
|
||||
% For automatic red background in solutions
|
||||
fill = \ORMCbgcolor,
|
||||
draw = none
|
||||
draw = none,
|
||||
rounded corners = 0mm
|
||||
},
|
||||
%
|
||||
% Nodes
|
||||
main/.style = {
|
||||
draw,
|
||||
circle,
|
||||
fill = white
|
||||
fill = white,
|
||||
line width = 0.35mm
|
||||
},
|
||||
accept/.style = {
|
||||
draw,
|
||||
circle,
|
||||
fill = white,
|
||||
double,
|
||||
double distance = 0.5mm,
|
||||
line width = 0.35mm
|
||||
},
|
||||
hatch/.style = {
|
||||
pattern=north west lines,
|
||||
pattern color=gray
|
||||
start/.style = {
|
||||
draw,
|
||||
rectangle,
|
||||
fill = white,
|
||||
line width = 0.35mm
|
||||
},
|
||||
%
|
||||
% Loop tweaks
|
||||
loop above/.style = {
|
||||
min distance = 2mm,
|
||||
looseness = 8,
|
||||
out = 45,
|
||||
in = 135
|
||||
},
|
||||
loop below/.style = {
|
||||
min distance = 5mm,
|
||||
looseness = 10,
|
||||
out = 315,
|
||||
in = 225
|
||||
},
|
||||
loop right/.style = {
|
||||
min distance = 5mm,
|
||||
looseness = 10,
|
||||
out = 45,
|
||||
in = 315
|
||||
},
|
||||
loop left/.style = {
|
||||
min distance = 5mm,
|
||||
looseness = 10,
|
||||
out = 135,
|
||||
in = 215
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user