GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Track a bounded suffix for a symbol counted from the right

2 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

Both require remembering the last k symbols to decide whether the kth-from-right symbol has the required value, then separating suffix histories to justify the minimal DFA size. The alphabet labels and k differ (three versus two);

1 mark · NAT
Report issue

Finite Automata

Question 22, GATE 2017: For L described by (a+b)*b(a+b) over {a,b}, find the smallest number of states in a deterministic finite automaton accepting L.
Tap to enlarge
Answer & solution

Official answer: 4.0

Our answer: 4

Step through it (2 parts)

1. The expression allows any prefix, then b, then exactly one final symbol. Thus acceptance depends on whether the second-last symbol is b, and words shorter than two are rejected.

2. Use states aa,ab,ba,bb representing the last two symbols, padding the initial short prefix on the left with a. Start at aa; on input z shift xy to yz. Accept ba and bb. All four states are reachable.

3. Two states with different first symbols have different acceptance immediately. If their first symbols agree but second symbols differ, append a; their new first symbols then differ. Every pair is distinguishable, proving the four-state construction minimal.

Original paper, page 11 · Answer key

5 marks · Descriptive
Report issue

Third-from-last bit: NFA and minimum DFA

Finite Automata

Question 17(b), GATE 1991: Let L be the set of binary strings whose third symbol from the right is 1. Construct an NFA for L and justify the number of states in its minimized equivalent DFA.
Tap to enlarge
Answer & solution

Answer: A four-state NFA suffices; the minimum DFA has exactly 8 states. (no official key was published)

The language is {0,1}*1{0,1}{0,1}. An NFA can guess which 1 will be third from last, then require exactly two more symbols before acceptance. Use states q0,q1,q2,q3; q0 is initial and q3 is the only accepting state. Missing transitions go to the empty set.

Transition table

State | on 0 | on 1
q0    | {q0} | {q0,q1}
q1    | {q2} | {q2}
q2    | {q3} | {q3}
q3    | {}   | {}

Equivalently, q0 has a loop labeled 0,1 and an additional edge labeled 1 to q1; q1→q2 and q2→q3 are labeled 0,1. A successful path stays at q0 through an arbitrary prefix, takes the guessing edge on a 1, and reads exactly two additional symbols. It ends in q3 precisely for the required strings.

For a DFA upper bound, store the most recent three bits, padding on the left with zeros before three bits have arrived. Use the eight states abc∈{0,1}^3, initial state 000, transition δ(abc,d)=bcd, and accepting states 100,101,110,111. After at least three inputs the first stored bit is exactly third from last; shorter strings remain nonaccepting because their padded first bit is zero. Every state is reachable by reading its three-bit label.

For minimality, take two different length-three strings x and y, differing at position r counted from the left, with 1≤r≤3. Append 0r−1 to both. In each resulting string, the third symbol from the right is precisely the old position r, so exactly one extension is accepted. Thus all eight three-bit strings have pairwise distinct right languages. By Myhill–Nerode, every DFA needs at least eight states. The construction meets this bound, proving that its minimized size is exactly 8.

Original paper, page 8