GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 51

Deterministic recognition of balanced brackets

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2003 paper

GATE 2003, Q51 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 51, GATE 2003: Let G=({S},{a,b},R,S), where R is S→aSb | SS | ε. Which statement is true?
A. G is not ambiguous.
B. There exist x,y in L(G) with xy not in L(G).
C. A deterministic pushdown automaton accepts L(G).
D. A deterministic finite-state automaton accepts L(G).
Question 51, GATE 2003: Let G=({S},{a,b},R,S), where R is S→aSb | SS | ε. Which statement is true?
A. G is not ambiguous.
B. There exist x,y in L(G) with xy not in L(G).
C. A deterministic pushdown automaton accepts L(G).
D. A deterministic finite-state automaton accepts L(G).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Interpret a as an opening bracket and b as a closing bracket. aSb encloses a balanced string, SS concatenates two balanced strings, and ε is balanced. Conversely, split any nonempty balanced string at its first matching close to obtain these productions.
2. A deterministic stack machine pushes on a, pops on b, rejects a pop from an empty stack, and accepts exactly with empty stack at end. This establishes C.
3. A is false: ε has both the direct S→ε tree and S→SS→εε. B is false because S→SS supplies closure under concatenation. D is false because intersecting with regular a*b* leaves the nonregular language {an bn:n≥0}.

Solution: The grammar generates balanced strings with a as opening bracket and b as closing bracket, including concatenations and the empty word. A deterministic pushdown automaton pushes on a, pops on b, rejects an unmatched b, and accepts at the end exactly when its stack is empty. Thus C is true. The grammar itself is ambiguous, for example ε can be produced directly or through S→SS with two empty children. Its language is closed under concatenation by S→SS and is not regular, since intersection with a*b* gives {aⁿbⁿ:n≥0}.

Original paper, page 7