MCS-212 · Block 2 Unit 2

Automata and Languages

Section 6 of 8

Block 2 · Unit 2Automata and Languages11 min · Section 6 of 8

2.6Designing finite automata

Covers IGNOU MCS-212 §2.4 exercises Ex.8–Ex.12, 2.7

Designing a DFA is a small programming task with a very limited memory: the current state is all the machine remembers. The art is to decide what information about the input read so far must be remembered, and to make one state for each possibility.

A design method

  1. Decide what the machine must remember after reading a prefix (parity of the length, the last two symbols, how many aa‘s up to 3, …). Each possible value becomes a state.
  2. Choose the start state (what is remembered after reading λ\lambda) and the final states.
  3. For each state and each symbol, decide the next state. Add a dead state if some prefixes can never lead to acceptance.
  4. Test on several strings that should be accepted and several that should be rejected.

Transition diagrams of three small DFAs

What a finite automaton cannot do

A DFA with kk states can only remember kk different things. Languages such as {anbn∣n≥0}\{a^nb^n \mid n \geq 0\}, “balanced brackets”, or “twice as many aa‘s as bb‘s” need a counter that can grow without limit, so no DFA recognises them. They need more powerful machines (pushdown automata, Turing machines — Unit 3).

Key takeaways

  • States = the information the machine must remember.
  • Use a dead state for prefixes that can never be accepted.
  • Test every design on accepted and rejected strings.
  • Languages that need unbounded counting (e.g. anbna^nb^n) are not regular and have no FA.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

What is the minimum number of states of a DFA over {a,b}\{a, b\} that accepts exactly the strings of even length?

Show answer

Answer: B. 2

The machine must distinguish “even so far” from “odd so far”. One state cannot do that; the 4-state machine in the study material works but is not minimal.

Question 2 · multiple choice

Which regular expression describes the even-length strings over {a,b}\{a, b\}?

Show answer

Answer: D. (aa+ab+ba+bb)∗(aa + ab + ba + bb)^*

Any number (including zero) of two-letter blocks. Option 1 has only the four strings of length 2.

Question 3 · multiple choice

Why is there no FA for “strings with twice as many aa‘s as bb‘s”?

Show answer

Answer: A. It needs an unbounded count, but an FA has finitely many states

The difference ”#aa − 2·#bb” can become arbitrarily large, so finitely many states cannot track it. Containing λ\lambda is no problem for an FA.

Question 4 · multiple choice

A DFA’s states mean “0 letters read”, “1 letter read”, “second letter was aa” (final, loops), “second letter was bb” (dead). Which string is accepted?

Show answer

Answer: C. babbab

The second letter of babbab is aa. aa has no second letter, and abbbabbb has bb second.

Question 5 · multiple choice

In the DFA that accepts only λ\lambda, what happens on the input aa?

Show answer

Answer: B. It moves to a dead state and rejects

Every non-empty string leads to the dead state. A DFA has a transition for every symbol, so option 3 cannot happen; and a DFA always stops after reading the input.

Question 6 · short answer

Design a DFA over {0,1}\{0, 1\} that accepts binary numbers (read from the most significant bit) divisible by 3. Give its states and transitions.

Show worked answer

Remember the remainder of the number read so far modulo 3: states r0r_0 (start, final), r1r_1, r2r_2. Reading bit bb changes the value nn to 2n+b2n + b, so the remainder rr becomes (2r+b) mod 3(2r + b) \bmod 3: δ(r0,0)=r0\delta(r_0, 0) = r_0, δ(r0,1)=r1\delta(r_0, 1) = r_1, δ(r1,0)=r2\delta(r_1, 0) = r_2, δ(r1,1)=r0\delta(r_1, 1) = r_0, δ(r2,0)=r1\delta(r_2, 0) = r_1, δ(r2,1)=r2\delta(r_2, 1) = r_2. Check 110110 (= 6): r0→r1→r0→r0r_0 \to r_1 \to r_0 \to r_0, accepted; 101101 (= 5): r0→r1→r2→r2r_0 \to r_1 \to r_2 \to r_2, rejected.

↑ ↓ move↵ openTab switch type