Given the following two languages : L1 = {an bn | n \(\geq\) 1} ∪ {a} L2 = {w…
2014
Given the following two languages :
L1 = {an bn | n \(\geq\) 1} ∪ {a}
L2 = {w C wR | w ∈ {a, b}* }
Which statement is correct ?
- A.
Both L1 and L2 are not deterministic.
- B.
L1 is not deterministic and L2 is deterministic.
- C.
L1 is deterministic and L2 is not deterministic.
- D.
Both L1 and L2 are deterministic.
Attempted by 64 students.
Show answer & explanation
Correct answer: B
Correct statement: L1 is not deterministic and L2 is deterministic.
Reason for L1 (a^n b^n ∪ {a}):
After reading the first symbol 'a', a machine must decide whether the input is the single string "a" or the beginning of a longer string of the form a^n b^n. A deterministic pushdown automaton (DPDA) cannot make that future-looking choice without nondeterminism.
Any DPDA that, on the first 'a', commits to pushing expecting b's will fail to accept the single string "a"; any DPDA that commits to accepting immediately cannot handle strings that require matching b's. Thus recognizing this union requires nondeterministic choices, so the language is not deterministic.
Reason for L2 ( { w C w^R | w ∈ {a,b}* }):
The marker C clearly separates the two halves. A DPDA can deterministically operate in two phases:
1) Push phase: while reading the prefix w (before C), push each symbol onto the stack.
2) Pop-and-match phase: upon reading C switch to a state that pops one stack symbol for each input symbol and checks it matches; accept if the stack is correctly emptied at the end.
All transitions are determined by the current state, the input symbol (or the marker C), and the top of stack, so this is a deterministic procedure.
Conclusion: L1 requires nondeterminism and thus is not a deterministic context-free language; L2 is recognized by a deterministic PDA. Therefore the correct choice states that L1 is not deterministic and L2 is deterministic.