Exercise

From a Drawing to a Definition, and Back

Practise moving between the two descriptions of a deterministic finite automaton (DFA): read a drawn automaton and write its formal definition, and draw an automaton from a definition; the tool checks every answer.

Last updated:


From a drawing to a definition

The lesson Deterministic Finite Automata gave two descriptions of a deterministic finite automaton (DFA):
a state diagram, and the formal definition (Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F)⁠, with the transition function δ\delta and the set of accepting states FF⁠.
Here you practise moving between them in both directions.

Question 1. The tool below shows a DFA over {a,b}\{a,b\}⁠. Read the drawn automaton and write its formal definition:
the set of states QQ⁠, the start state q0q_0⁠, the set of accepting states FF and the transition function δ\delta⁠.
Choose the target of every state on every letter, then press “Check the definition”.

The workbench needs JavaScript. Use the question on paper instead.

Hint

Name the states in the drawing, then follow the arrows of one state at a time.
Every state has exactly one arrow on aa and one on bb⁠.
The accepting states are drawn with a double circle, and the start state has an arrow that comes from nowhere.

Answer

Q={q0,q1,q2,q3}Q=\{q_0,q_1,q_2,q_3\}⁠, start state q0q_0⁠, F={q2}F=\{q_2\}⁠, and δ(q0,a)=q1\delta(q_0,a)=q_1⁠, δ(q0,b)=q3\delta(q_0,b)=q_3⁠, δ(q1,a)=q1\delta(q_1,a)=q_1⁠, δ(q1,b)=q2\delta(q_1,b)=q_2⁠, δ(q2,a)=q1\delta(q_2,a)=q_1⁠, δ(q2,b)=q2\delta(q_2,b)=q_2⁠, δ(q3,a)=δ(q3,b)=q3\delta(q_3,a)=\delta(q_3,b)=q_3⁠.
The automaton accepts the words that start with aa and end with bb⁠, and q3q_3 is a rejecting trap.

From a definition to a drawing

How to use the workbench
  1. Double-click an empty place to add a state, and drag a state to move it. Double-click a state to make it accepting, or not accepting.
  2. Hold Shift and drag from an empty place to a state to mark it as the start state (drag the tail of its arrow to move or resize it). Hold Shift and drag from a state to another state (or back to the same state) to draw an arrow, then type its letters, separated by commas, and press Enter. Drag an arrow to bend it, and press Delete or Backspace to remove the selected state or arrow.
  3. Everything the drawing can do can also be done in the list of states and the transition table, with a keyboard or on a touch screen.
  4. Choose what to check against, and press “Check”. A deterministic finite automaton (DFA) must have exactly one arrow from every state on every letter; the workbench lists what is missing.

Question 2. Let A=(Q,Σ,δ,q0,F)A=(Q,\Sigma,\delta,q_0,F) with Q={q0,q1,q2}Q=\{q_0,q_1,q_2\}⁠, Σ={0,1}\Sigma=\{0,1\}⁠, start state q0q_0⁠, F={q0}F=\{q_0\} and δ(qi,c)=q(2i+c) mod 3\delta(q_i,c)=q_{(2i+c)\bmod 3} for i∈{0,1,2}i\in\{0,1,2\} and every bit c∈{0,1}c\in\{0,1\}⁠.
Draw this automaton in the tool below, with the state names of the definition, and press “Check”.
Then say which words it accepts.

The workbench needs JavaScript. Use the question on paper instead.

Hint

Compute δ(qi,c)\delta(q_i,c) for each of the six pairs, for example δ(q1,0)=q(2⋅1+0) mod 3=q2\delta(q_1,0)=q_{(2\cdot1+0)\bmod 3}=q_2⁠.
Then draw one arrow for each pair.

Answer

δ(q0,0)=q0\delta(q_0,0)=q_0⁠, δ(q0,1)=q1\delta(q_0,1)=q_1⁠, δ(q1,0)=q2\delta(q_1,0)=q_2⁠, δ(q1,1)=q0\delta(q_1,1)=q_0⁠, δ(q2,0)=q1\delta(q_2,0)=q_1⁠, δ(q2,1)=q2\delta(q_2,1)=q_2⁠. The state qiq_i means that the binary number read so far leaves remainder ii when divided by 33⁠, so the automaton accepts the binary numbers that are divisible by 33 (and the empty word).

Back to Deterministic Finite Automata, or see the glossary.