ToC Assignment Solution (1)
ToC Assignment Solution (1)
Context-Free Grammar (CFG): A set of production rules generating a language where every
derivation has a single parse tree.
Unambiguity: A grammar is unambiguous if every string has a unique parse tree.
1. Normalization Steps:
Remove null, unit, and useless productions.
Convert to Chomsky Normal Form (CNF): Every rule is A → BC or A → a.
Convert to Greibach Normal Form (GNF): Every rule is A → aα, where α is a string of
variables.
S → AB, A → 011 ∣ 1, B → 01
Let me know if you'd like detailed explanations for specific questions or visual aids like diagrams for
automata!
1. Definitions
Finite Automata (FA): A mathematical model used to recognize regular languages. It consists of:
A finite set of states (Q).
An input alphabet (Σ).
A transition function (δ ).
An initial state (q0 ).
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 4/7
Example: Recognizing binary strings divisible by 2.
Q = {q0 , q1 }, Σ = {0, 1}, q0 is the initial state, and F = {q0 }.
ε-closure(q): The set of all states reachable from q using zero or more ϵ-transitions.
ϵ ϵ
q0 q1 , q1 q2
ϵ-closure(q0 ) = {q0 , q1 , q2 }.
1
Transition qi q(i+1) mod 4 .
Diagram:
0 0 0
q0 q1 q2 q3 .
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 5/7
Non-deterministic because it doesn't reset progress for other inputs.
States:
q0 : Even 1’s and Even 0’s (Initial state).
4. L2 : 0(0 + 1)∗ 1.
S → aSb ∣ bSa ∣ ϵ
CFG is unambiguous if every string in the language has only one parse tree.
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 6/7
12. CNF and GNF Conversion
Convert productions:
CNF: Every production A → BC or A → a.
GNF: A → aα, where α is a string of variables.
S → AB, A → 011 ∣ 1, B → 01
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 7/7