State diagrams

Published

2023-09-04

We may represent a finite automaton by its formal definition and as a state digram. These two representations are equivalent. It’s often (but not always) the case that a state diagram gives us a better intuition of how a particular finite automaton works. While the formal description and the diagram are equivalent, one can be easier to interpret than the other. Accordingly, we’ll learn both representations, and with some practice you should be able to perform the following tasks:

For example, here’s a formal definition of a DFA:

M_1 = (Q, \Sigma, \delta, q_1, F)

Q = \{q_1, q_2, q_3\}

\Sigma = \{0, 1\}

\delta = \begin{cases} q_2 & (q_1, 0) \\ q_3 & (q_1, 1) \\ q_2 & (q_2, 0) \\ q_3 & (q_2, 1) \\ q_2 & (q_3, 0) \\ q_3 & (q_3, 1) \end{cases}

F = \{q_1\}.

(If you’re not used to notation for piecewise functions, you can read this as “transition to q_2 if in q_1 and symbol is 0; transition to q_3 if in q_1 and symbol is 1; etc.)

We can construct a corresponding state diagram thus:

  1. For each element in Q draw a circle to represent q_i \in Q.

  1. For each element in F draw a second circle, nested within the first, to indicate accept states (if any).

  1. The forth element of the tuple (in the formal definition) is the start state. There can be only one. Indicate the start state in the digram by drawing an arrow from nothing to the start state. (Note: It’s best to think of the arrow thus drawn solely as an indicator of the starting state, and not as a directed edge in the graph proper.)

  1. Now, for each piece of the piecewise function \delta draw a directed edge corresponding to that piece. For example, the first piece of \delta is \delta(q_1, 0) = q_2. That’s represented by an arrow from q_1 to q_2, labeled with 0. (This means, if the machine is in state q_1 and the next symbol of input is 0, then the machine transitions to state q_2.

Here’s the diagram after adding the first such edge:

Here’s the completed diagram:

Notice that we could have drawn it with the state circles in different positions. We might do this for aesthetic reasons, or perhaps for readability, but in no way does this change the information content of the diagram or the machine it represents.

Note that there has to be an out edge corresponding to each symbol in \Sigma for each state in Q (keeping in mind shorthand options, below).

Shorthand and abbreviations

Sometimes there’s a little “shorthand” permitted in drawing such diagrams. For example, let’s say we have this machine:

M_2 = (Q, \Sigma, \delta, q_1, F)

Q = \{q_1, q_2, q_3\}

\Sigma = \{0, 1\}

\delta = \begin{cases} q_2 & (q_1, 0) \\ q_3 & (q_1, 1) \\ q_2 & (q_2, 0) \\ q_2 & (q_2, 1) \\ q_3 & (q_3, 0) \\ q_3 & (q_3, 1) \end{cases}

F = \{q_1\}.

One way to draw this would be

Notice that we have two labels on two separate edges. This is a convenient way of representing two transitions with a single edge.

Since our alphabet is \Sigma = \{0, 1\}, we could also label these edges thus:

Notice that this shorthand applies to edges and their labels. We cannot combine states in any similar way.

Comprehension check / exercises

  1. Describe in plain English the language recognized by finite automaton M_1.

  2. Write the language recognized by M_1 using set builder notation. You may refer to this language as \mathcal{L}_1.

  3. Describe in plain English the language recognized by finite automaton M_2.

  4. Write the language recognized by M_2 using set builder notation. You may refer to this language as \mathcal{L}_2.

  5. Soon, we’ll see how to construct a finite automaton that recognizes the intersection of two languages. For now, an informal answer to this question will suffice: What is the intersection of \mathcal{L}_1 and \mathcal{L}_2?

  6. Given the following formal definition of M_3, produce an equivalent state diagram.

\hspace{2em}M_3 = (Q, \Sigma, \delta, q_1, F)

\hspace{2em}Q = \{q_1, q_2, q_3, q_4\}

\hspace{2em}\Sigma = \{0, 1\}

\delta = \begin{cases} q_2 & (q_1, 0) \\ q_4 & (q_1, 1) \\ q_3 & (q_2, 0) \\ q_1 & (q_2, 1) \\ q_4 & (q_3, 0) \\ q_2 & (q_3, 1) \\ q_1 & (q_4, 0) \\ q_3 & (q_4, 1) \end{cases}

\hspace{2em}F = \{q_1\}.

  1. Write down the formal definition of M_4, which corresponds to the following state diagram:

  1. Describe in plain English the language recognized by M_4.

Warning: Clayton’s pet peeve

Consider the following (hypothetical) student submission. Please don’t do this. Make sure that both endpoints of any directed edge actually touch the corresponding state. The start state indicator should touch the start state at the end with the arrow.

I have yet to deduct points for such diagrams (unless they are otherwise incorrect)—though sometimes they elicit snarky comments (I try not to, but forgive me, it does happen sometimes). Be kind to your instructor’s eyeballs, and don’t be the first student who loses points for this.

(Remarkably, there is one textbook I’m aware of that actually does this for all state diagrams! Horrors!)

Copyright © 2023 Clayton Cafiero. All rights reserved.