0% found this document useful (0 votes)
68 views7 pages

Autometa Solution

The document outlines a theory examination for a B.Tech course on Formal Language & Automata Theory, including definitions and comparisons of key concepts such as alphabets, DFAs, NFAs, and context-free grammars. It also covers the Chomsky hierarchy, properties of regular languages, and the construction of DFAs, along with detailed explanations and examples. Additionally, it discusses the closure properties of regular languages and provides insights into Mealy and Moore machines.

Uploaded by

vksnp111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views7 pages

Autometa Solution

The document outlines a theory examination for a B.Tech course on Formal Language & Automata Theory, including definitions and comparisons of key concepts such as alphabets, DFAs, NFAs, and context-free grammars. It also covers the Chomsky hierarchy, properties of regular languages, and the construction of DFAs, along with detailed explanations and examples. Additionally, it discusses the closure properties of regular languages and provides insights into Mealy and Moore machines.

Uploaded by

vksnp111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CHANDIGARH ENGINEERING

COLLEGE, JHANJERI, MOHALI


(An Autonomous Institute under UGC Act)

— Theory Examination – I
Course: B.Tech — Semester: 5th — Time: 1.5 Hrs
Branch: AIML — Subject Code: BTCS 502-18 — MM: 24
Subject: Formal Language & Automata Theory

SECTION A (Each 1 mark — detailed answers)


Q.1 a) Alphabet (Σ) — detailed

An alphabet Σ is a finite, non-empty set of atomic symbols (tokens).

 Formal: Σ is a set; elements are called symbols or letters.


 Strings: A string (or word) over Σ is a finite sequence of symbols from Σ. The empty
string is ε (length 0). The set Σ* denotes all finite strings over Σ.
 Examples: Σ = {0,1} (binary), Σ = {a,b,c}.
 Usage: Languages are subsets of Σ*. Grammars and automata operate on symbols
from Σ.

Q.1 b) DFA vs NFA — detailed comparison

Definitions

 DFA (Deterministic Finite Automaton): A 5-tuple (Q, Σ, δ, q₀, F) where δ: Q × Σ


→ Q is total (exactly one next state).

× (Σ ∪ {ε}) → P(Q). From a state and symbol (or ε) the machine may move to zero,
 NFA (Nondeterministic Finite Automaton): A 5-tuple (Q, Σ, Δ, q₀, F) where Δ: Q

one, or many states.

Key differences

 Determinism: DFA has exactly one move; NFA can have many/none.
 ε-transitions: NFAs may use ε-moves, DFAs cannot.
 Ease of design: NFAs often simpler to design; DFAs easier to implement.
 Power: Both recognize exactly the regular languages (equivalent expressive power).
 Conversion: Every NFA can be converted to an equivalent DFA by subset
construction (possibly exponential blow-up).
 Running time: DFA processes input in O(n) with single transition per symbol; NFA
can be simulated with backtracking or converted to DFA.
Example: NFA for language “strings containing substring 01” is small; corresponding DFA
may need more states.

Q.1 c) Example of a production rule in a Context-Free Grammar (CFG)

α where A ∈ V, α ∈ (V ∪ Σ)*), start symbol S.


A CFG is a 4-tuple (V, Σ, R, S) with non-terminals V, terminals Σ, production rules R (A →

Example rule: S → a S b | ε
This rule says S can produce a S b or the empty string. This grammar generates L = { aⁿ bⁿ |
n ≥ 0 }.

Q.1 d) Pumping Lemma for regular languages — organized statement

Statement: If L is an infinite regular language then there exists an integer p ≥ 1 (the pumping
length) such that every string w in L with |w| ≥ p can be written as w = xyz satisfying:

1. |xy| ≤ p,

3. For all i ≥ 0, x yⁱ z ∈ L.
2. |y| ≥ 1,

pumping length p, pick a specific w ∈ L with |w| ≥ p, show for every split w=xyz satisfying
Use: Contrapositive use: to show a language is not regular, assume it is regular, take its

(1)-(2) there exists i such that x yⁱ z ∉ L → contradiction.

SECTION B (Each 4 marks — detailed answers)


Q.2 Chomsky Hierarchy — full classification with grammar forms and
examples

Chomsky hierarchy (four types):

o Grammar: Productions of form α → β where α, β ∈ (V ∪ Σ)*, α contains at


1. Type-0 (Unrestricted grammars / Recursively enumerable languages)

least one non-terminal.


o Recognizer: Turing machine.
o Example: L = { aⁿ bⁿ cⁿ | n ≥ 0 } is Type-0 (not context-free).

o Grammar: Productions αAβ → αγβ where A ∈ V and γ ≠ ε and |αγβ| ≥ |αAβ|


2. Type-1 (Context-Sensitive grammars / Context-sensitive languages)

(length of RHS ≥ LHS). No shrinking except possibly S → ε under specific


conditions.
o Recognizer: Linear Bounded Automaton (LBA).
o Example: L = { aⁿ bⁿ cⁿ | n ≥ 1 } is context-sensitive.
o Grammar: Productions of form A → γ where A ∈ V and γ ∈ (V ∪ Σ)*.
3. Type-2 (Context-Free grammars / Context-free languages)

o Recognizer: Push-Down Automaton (PDA).


o Example: L = { aⁿ bⁿ | n ≥ 0 }.
4. Type-3 (Regular grammars / Regular languages)
o Grammar: Right-linear (A → aB or A → a) or left-linear (A → Ba or A → a).
o Recognizer: Finite Automata (DFA/NFA/RE).
o Example: L = { 0* 1* } or L = { w | w ends with 01 }.

Inclusion: Regular ⊂ Context-free ⊂ Context-sensitive ⊂ Recursively enumerable.

Q.3 Regular languages — definition, properties, and three detailed examples

Definition (again): A language L ⊆ Σ* is regular iff it can be described by a regular


expression, or accepted by a finite automaton (DFA/NFA), or generated by a right/left-linear
grammar.

Properties: closed under union, concatenation, Kleene star, complement, intersection,


difference, homomorphism, inverse homomorphism.

Examples (with explanation & automata/regex):

1. L₁ = { 0ⁿ | n ≥ 0 }
o Regex: 0*.
o DFA: single accepting state q with δ(q,0)=q and δ(q,1)=sink (if alphabet

2. L₂ = { w ∈ {0,1}* | w ends with 01 }


includes 1).

o Regex: (0+1)*01.
o DFA: three states q0 (start), q1 (saw 0), q2 (saw 01) with q2 accepting.
Transition structure as earlier.
3. L₃ = { aⁿ bᵐ | n,m ≥ 0 } (a* b*)
o Regex: a*b*.
o DFA: states that accept any number of a's, once a b seen, only b's allowed;
trivial small DFA.

Q.4 Construct DFA that accepts binary strings ending with 01 — fully detailed

Language: L = { w ∈ {0,1}* | w ends with 01 }.

Intuition: We only need to remember last two symbols; hence at most 3 useful states (start,
last symbol was 0, last two were 01).

Formal DFA: M = (Q, Σ, δ, q₀, F) where

 Q = { q0, q1, q2 }
 Σ = { 0, 1 }
 q₀ = q0
 F = { q2 }
 δ defined:

Current Input Next


q0 0 q1
q0 1 q0
q1 0 q1
q1 1 q2
q2 0 q1
q2 1 q0

Explanation:

 q0: no recent 0 (or last symbol was 1 or start).


 q1: last symbol seen is 0 (so candidate for 01).
 q2: the last two symbols are 01 — ACCEPT state. Further inputs update the two-last-
symbol memory accordingly.

Proof of correctness (sketch): By induction on length of input show state tracks whether
suffix is length 0, suffix ends with 0, or suffix ends with 01.

SECTION C (8 marks — detailed long answers)


Q.5(a) Detailed note on regular language properties and closure proofs (with
constructive proofs for union and concatenation)

Closure under union (constructive proof using product automaton / NFA construction):
Given DFAs M₁ = (Q₁, Σ, δ₁, q₁₀, F₁) for L₁ and M₂ = (Q₂, Σ, δ₂, q₂₀, F₂) for L₂,
construct DFA M = (Q₁ × Q₂, Σ, δ, (q₁₀,q₂₀), F) where:

F = { (p,q) | p ∈ F₁ or q ∈ F₂ }.
 δ((p,q), a) = (δ₁(p,a), δ₂(q,a)).

M accepts exactly L₁ ∪ L₂: run both machines in parallel; accept if either accepts. This
shows regular languages are closed under union.

Closure under concatenation (NFA construction):


Given NFAs for L₁ and L₂, construct an NFA for L₁·L₂ by adding ε-transitions from each
final state of NFA₁ to the start state of NFA₂; the start is NFA₁'s start; final states are
NFA₂'s finals. If both given as DFA, convert to NFA or use product construction with extra
bookkeeping (or convert to regex and combine).

Kleene star closure: For NFA of L, create new start/accept state with ε-transition to old start,
and ε-transitions from old final states back to old start.
Complement and intersection: Since regular languages are closed under complement (use
DFA and swap final/non-final states), and intersection can be achieved via product
construction with F = F₁ × F₂, closure under intersection follows.

Q.5(b) Mealy vs Moore machines — formal definitions, example, pros/cons

Moore machine: 6-tuple (Q, Σ, Δ, δ, λ, q₀) where λ: Q → Γ gives output determined solely
by the current state. Output is associated with states.

Mealy machine: 6-tuple (Q, Σ, Δ, δ, ω, q₀) where ω: Q × Σ → Γ gives output based on


current state and input symbol.

Example (binary input → output is previous input):

 Mealy can output on transitions, often fewer states needed.


 Moore outputs per state; outputs change only when entering a state.

Pros/Cons:

 Mealy: potentially fewer states (smaller), outputs may change faster (on input).
 Moore: outputs stable per state (easier to synchronize), simpler timing.

Application: Both used in digital circuit design, protocol encoders/decoders, and sequential
logic modeling.

Q.5(c) DFA vs NFA — with formal conversion sketch and example

Equivalence proof sketch (NFA → DFA): Subset construction: each DFA state corresponds

state S and input a compute T = ε-closure( ∪_{p∈S} Δ(p,a) ). Mark any DFA state
to a set of NFA states (including ε-closure). Start state is ε-closure({q₀}). For every DFA

containing an NFA final as accepting. This yields a DFA that accepts same language.

Example: NFA with ε-transitions accepting (ab|a) is easily converted to DFA via subset
construction.

Q.5(d) Derivations in CFGs — leftmost vs rightmost with parse trees &


example

CFG recap: Productions A → α.

Derivation: A sequence of rule applications starting from S to produce string w ∈ Σ*.


Leftmost derivation (LM): Always replace the leftmost non-terminal at each step.
Rightmost derivation (RM): Always replace the rightmost non-terminal.

Example grammar:
S→AB
A→aA|a
B→bB|b

Generate: aaabbb

Leftmost: S ⇒ A B ⇒ a A B ⇒ aa A B ⇒ aaa B ⇒ aaa b B ⇒ aaa bb ⇒ aaa bbb


Rightmost: S ⇒ A B ⇒ A b B ⇒ A b b ⇒ a A b b ⇒ a a b b ⇒ etc (replace


rightmost at each step)

Parse tree: Both LM and RM correspond to the same parse tree (unique tree if grammar is
unambiguous). The parse tree visually shows hierarchical structure of derivation.

Worked example: Minimization of DFA (from earlier


optional question)
Given DFA with states {A, B, C, D}, alphabet {0,1}, start A, accept {C, D}, transitions:

 δ(A,0)=B, δ(A,1)=C
 δ(B,0)=A, δ(B,1)=D
 δ(C,0)=D, δ(C,1)=A
 δ(D,0)=C, δ(D,1)=B

Minimization using partition refinement (Hopcroft / table-filling):

1. Initial partition: Final states {C, D} and non-final {A, B}.


2. Check distinguishability:
o For {A,B}: under input 0, A→B (non-final), B→A (non-final) — both stay in
{A,B}; under 1, A→C (final), B→D (final) — both go to finals. So A and B
are indistinguishable so far.
o For {C,D}: under 0, C→D (final), D→C (final); under 1, C→A (non-final),
D→B (non-final) — both behave symmetrically. So C and D are
indistinguishable.
3. No further refinement; final partition blocks: {A,B} and {C,D}. Therefore minimal
DFA has 2 states: [AB], [CD] with transitions derived from representatives. Start state
[AB], Accepting [CD]. This is the minimized DFA.

Construct minimized transition table: Choose representative A for [AB], C for [CD]:

State 0 1 Accept?
[AB] [AB] (since A→B→belongs to [AB]) [CD] (A→C) No
[CD] [CD] (C→D→[CD]) [AB] (C→A) Yes
This 2-state machine correctly captures the same language.

Detailed Pumping Lemma proof (classical example: L =


{ aⁿ bⁿ | n ≥ 0 } is not regular)
Claim: L = { aⁿ bⁿ | n ≥ 0 } is not regular.

Proof by contradiction using pumping lemma:

2. Choose w = aᵖ bᵖ ∈ L (|w| = 2p ≥ p).


1. Assume L is regular. Then pumping lemma holds: there exists p ≥ 1.

3. By the lemma, w = x y z with |xy| ≤ p and |y| ≥ 1. Because |xy| ≤ p, both x and y
consist only of a’s (the first p symbols are all a). So y = a^k where k ≥ 1.

L must have equal number of a’s and b’s. Thus x z ∉ L.


4. Pump i = 0: x y⁰ z = x z. That string has aᵖ⁻ᵏ bᵖ (fewer a’s than b’s). But any string in

5. This contradicts the pumping lemma requirement that x yⁱ z ∈ L for all i ≥ 0. Hence L
is not regular.

Key idea: Because the pumping section y lies entirely in the a-block, removing it makes
counts unequal.

You might also like