GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Track length residues and handle empty-string acceptance

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

How these are solved

Use length modulo a fixed divisor to recognize multiples, explicitly checking whether the empty string is accepted. The positive-multiple restriction in 2011 changes the initial-state treatment and is not just a numerical repeat.

2 marks · MCQ
Report issue

Positive multiples of a fixed unary length

Finite Automata

Question 42, GATE 2011: Over alphabet {a}, let L={a^(nk): k>0}, where n is a fixed positive integer. What is the minimum number of states in a DFA recognizing L?

(A) k+1
(B) n+1
(C) 2^(n+1)
(D) 2^(k+1)
Tap to enlarge
Your answer
Answer & solution

Official answer: B

The language is {ank: k>0}, where n is a fixed positive integer; epsilon is excluded. Use a separate nonaccepting start state, then an n-state cycle that records the positive input length modulo n, accepting the residue-zero state. This uses n+1 states. For minimality, the n positive residue classes are pairwise distinguishable by an extension that makes exactly one length divisible by n. The empty prefix is distinguished from a positive multiple of n by the empty suffix, and from each other positive residue by a suffix that completes that residue to a multiple of n. Thus all n+1 classes are necessary, option B.

An explicit construction uses start z and cycle states r0,...,r(n-1). The first a moves z to r(1 mod n); each subsequent a advances the residue by one modulo n; only r0 is accepting. z must reject epsilon whereas r0 accepts it, so the usual n-state modulo counter cannot merge these two states. For n=1 the result is two states, recognizing a+ rather than a*, which also checks the boundary case.

Original paper, page 11 · Answer key

2 marks · MCQ
Report issue

Automaton for lengths divisible by three

Finite Automata

Question 2.13, GATE 2002: How many states does the smallest finite automaton need to accept all strings whose lengths are divisible by 3?
(A) 2; (B) 3; (C) 4; (D) 5.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Explain both construction and minimality.

Step 2: Label states 0,1,2 and send each state to its successor modulo 3 for every input symbol. Start and accept at 0. To distinguish residues r≠s, append a word of length(3−r) mod3: the state r accepts afterward and s does not. Thus no two residue states can be merged in a deterministic automaton.

Conclusion: Use three states for the input length modulo 3, advance the residue on every symbol, and accept residue 0. The three residues are distinguishable: append a length that brings one chosen residue to 0; it does not bring a different residue to 0. Thus a minimal DFA has 3 states, B, over a nonempty alphabet.

Original paper, page 5