GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 21

Closure under prefixes and reversal

Theory of Computation · Closure Properties & Language Hierarchy · Full GATE CSE 1997 paper

GATE 1997, Q21 5 marks · Descriptive
Report issue

Closure Properties & Language Hierarchy

Question 21, GATE 1997: A language L is accepted by a finite-state machine. Prove that finite-state machines also accept L′={s: ss′∈L for some string s′} and Lᴿ={s: s is the reversal of some string in L}.
Tap to enlarge
Answer & solution

Answer: For prefixes, accept all states that can reach an old final state. For reversal, reverse edges and exchange starts/finals using an ε-NFA. (no official key was published)

Begin with a DFA M=(Q,Σ,δ,q0,F) for L. This loses no generality because any finite-state recognizer can be determinized. The two constructions solve different problems: L′ consists of prefixes that can still be completed to an accepted word; Lᴿ reverses complete accepted words.

Prefix construction: compute C={q∈Q: δ*(q,t)∈F for some t∈Σ*}. These are exactly the states from which some accepting state is reachable, found by a reverse graph search starting at F. Keep Q,Σ,δ,q0 unchanged and replace the accepting set F by C. The new machine accepts s precisely when δ*(q0,s) belongs to C, which is equivalent to the existence of t with δ*(q0,st)∈F. That is exactly s∈L′. No new states are needed. If L is nonempty, q0∈C and ε is a prefix; if L is empty, C is empty and no word is accepted.

Reversal construction: retain all old states and reverse every labeled transition. For each δ(p,a)=q, add an a-transition q→p. Introduce a fresh start state r with ε-transitions to every f∈F, and make q0 the sole final state. The result is generally nondeterministic because reversing edges can create several transitions with the same label. A path q0 --a1...an--> f in the old machine becomes f --an...a1--> q0 in the new one, and the converse follows by reversing the path again. Thus exactly the reversed words are accepted. If a DFA is required, apply ε-closure and subset construction. Simply exchanging start/final states without reversing edges, or reversing edges while insisting on a single old final as start, would not establish closure for arbitrary L.

Original paper, page 9