\begin{solution}{6} See figure \ref{fig:9.6}. \begin{figure*}[p] \centering \begin{tikzpicture}[->, node distance=2cm] \node[state,initial] (q0) {$q_0$}; \node[state] (q1) [right=of q0] {$q_1$}; \node[state] (q2) [right=of q1] {$q_2$}; \node[state] (q3) [right=of q2] {$q_3$}; \node[state] (q4) [below=of q1] {$q_4$}; \node[state] (q5) [below=of q4] {$q_5$}; \node[state] (qf) [right=of q4] {$q_f$}; \draw (q0) -- node[above] {$B/B,R$} ++ (q1); \draw (q1) -- node[above] {$a/X,R$} ++ (q2); \draw (q2) edge[loop above] node[above,align=center] {$a/a,R$\\$Y/Y,R$} (q2); \draw (q2) -- node[above] {$b/Y,L$} ++ (q3); \draw (q3) edge[loop right] node[right,align=left] {$a/a,L$\\$Y/Y,L$} (q3); \draw (q3) edge[bend right, out=300, in=240, looseness=1.3] node[above] {$X/X,R$} (q1); \draw (q1) -- node[left,align=right] {$B/B,R$\\$Y/Y,R$} ++ (q4); \draw (q4) edge[loop left] node[left] {$b/b,R$} (q4); \draw (q4) -- node[left] {$B/B,R$} ++ (q5); \draw (q1) -- node[above right] {$b/b,R$} ++ (qf); \draw (q2) -- node[above right,align=left] {$B/B,R$\\$X/X,R$} ++ (qf); \draw (q3) -- node[below right,align=left] {$b/b,R$\\$B/B,R$} ++ (qf); \draw (q4) -- node[below,align=center] {$a/a,R$\\$X/X,R$\\$Y/Y,R$} ++ (qf); \draw (qf) edge[out=300,in=330,looseness=8] node[below right,align=left] {$B/B,R$\\$a/a,R$\\$b/b,R$\\$X/X,R$\\$Y/Y,R$} (qf); \end{tikzpicture} \caption{The state machine of exercise 9.6.} \label{fig:9.6} \end{figure*} All is needed is to add a state $q_f$ in which we can loop forever for every undefined transition, except those of the final state(s). \end{solution}