0% found this document useful (0 votes)
8 views21 pages

Socks

The document discusses automata theory, focusing on finite automata, pushdown automata, and Turing machines. It covers concepts such as state transitions, grammars, and the languages generated by various types of grammars. Additionally, it addresses differences between deterministic and non-deterministic automata, closure properties of languages, and provides examples of derivation trees and automata design.

Uploaded by

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

Socks

The document discusses automata theory, focusing on finite automata, pushdown automata, and Turing machines. It covers concepts such as state transitions, grammars, and the languages generated by various types of grammars. Additionally, it addresses differences between deterministic and non-deterministic automata, closure properties of languages, and provides examples of derivation trees and automata design.

Uploaded by

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

Questions and Answers

1. What is the primary purpose of automata theory?


Answer: The primary purpose of automata theory is to study abstract
machines (automata) and the problems they can solve, particularly
focusing on computation, formal languages, and the relationship between
machines and languages.

2. A finite automaton is formally described as a 5-tuple (Q, Σ, δ, q0, F). State


the names of these parameters.
Answer:
o Q: Set of states

o Σ: Input alphabet

o δ: Transition function

o q0: Initial state

o F: Set of final (accepting) states

3. What is the relationship between the first three parameters?


Answer: The transition function (δ) maps a state in Q and an input symbol
from Σ to a new state in Q.

4. Write down the regular expression of all strings of 0's and 1's such that
the start symbol and end symbol are always the same/different.
Answer:
o Same: 0(0+1)*0 + 1(0+1)*1

o Different: 0(0+1)*1 + 1(0+1)*0

5. State whether the string 000101100111 is accepted by the machine


shown in Figure 1, or not. If not, then what is the final state?
Answer: Based on the transitions in Figure 1, the final state is q2, and since
q2 is not a final state, the string is not accepted.

1
6. Draw the transition table of the machine depicted in Figure 1.
Answer:
State Input: 0 Input: 1
q0 q1 q0
q1 q2 q1
q2 q2 q2
7.
What change do you suggest in the machine, shown in Figure 1, so that
it’ll accept only those strings, which end with 11?
Answer: Add a transition such that q1 transitions to q2 on input 1, and
make q2 the final state.

8. What change do you suggest in the machine, shown in Figure 1, so that


it’ll accept only those strings, which contain at least two 1's?
Answer: Make q2 a final state to accept strings containing at least two 1's.

9. Consider a grammar G with the production rules S -> Ab; A -> aAb; A -> λ.
Describe the language generated by this grammar.
Answer: The language generated is L = { a^n b^n b | n >= 0 }.

10. Consider a grammar G with the production rules S -> aSb; S -> λ.
Describe the language generated by this grammar.
Answer: The language generated is L = { a^n b^n | n >= 0 }.

11. State why epsilon transitions are required.


Answer: Epsilon transitions allow automata to move between states
without consuming an input symbol, enabling simplifications in design and
handling non-determinism.

2
12. State three differences between a DFA and an NFA.
Answer:
o DFA has a single transition for each input from a state, while NFA can

have multiple or epsilon transitions.


o DFA is deterministic; NFA is non-deterministic.

o Every DFA is an NFA, but not every NFA is a DFA.

13. While defining a Push Down Automata, what is the relationship


between Σ (The Set of Input Symbols) and Γ (The Set of Stack Symbols)?
Answer: Σ is a subset of Γ, as stack symbols can include input symbols
along with additional symbols for stack operations.

14. The formal definition of a Push Down Automata uses a 7-tuple (Q,
Σ, Γ, δ, q0, Z0, F), where δ: Q × (Σ ∪ {ε}) × Γ -> finite subsets of Q × Γ.
Explain.*
Answer: The transition function δ takes the current state, input symbol (or
epsilon), and top stack symbol, and maps them to a set of next states with
updated stack configurations.

15. Give an example each of (i) A ‘Null Production’ and (ii) A ‘Unit
Production’.
Answer:
o Null Production: A -> λ

o Unit Production: A -> B, where A and B are non-terminals.

16. When a grammar is said to be ambiguous? Give an example.


Answer: A grammar is ambiguous if a string can have more than one parse
tree.
Example: Grammar S -> SS | (S) | λ for string ()().

3
17. State the rules allowed when a grammar is in Chomsky Normal
Form.
Answer:
o Productions are of the form A -> BC or A -> a, where A, B, C are non-

terminals and a is a terminal.


o λ-productions are only allowed for the start symbol.

18. State the rules allowed when a grammar is in Greibach Normal


Form.
Answer: The productions are of the form A -> aα, where a is a terminal and
α is a string of non-terminals.

19. Which closure properties are valid for CFL, but not for RL? Which
closure properties are valid for RL, but not for CFL?
Answer:
o CFL is closed under union, concatenation, and Kleene star but not

under intersection or complementation.


o RL is closed under intersection and complementation but not under

union.

20. List the types of automatons and its acceptable languages and
grammars.
Answer:
o Finite Automaton (FA): Accepts Regular Languages (RL), generated by

Regular Grammars (RG).


o Push Down Automaton (PDA): Accepts Context-Free Languages

(CFL), generated by Context-Free Grammars (CFG).


o Turing Machine (TM): Accepts Recursively Enumerable Languages

(REL), no specific grammar.

4
21. Define Left and Right Linear Grammar.
Answer:
• Left Linear Grammar: The productions are of the form A -> Ba or A -> a,

where A and B are non-terminals and a is a terminal.


• Right Linear Grammar: The productions are of the form A -> aB or A -> a,

where A and B are non-terminals and a is a terminal.

21. State the formal definition of a Push Down Automata (PDA).


Answer: A PDA is a 7-tuple (Q, Σ, Γ, δ, q0, Z0, F), where:
• Q: Set of states

• Σ: Input alphabet

• Γ: Stack alphabet

• δ: Transition function (Q × (Σ ∪ {ε}) × Γ -> finite subsets of Q × Γ*)

• q0: Initial state

• Z0: Initial stack symbol

• F: Set of final states

22. Explain what do you mean by ‘Storage in State’ in context to


extensions of Turing Machine?
Answer: 'Storage in State' refers to using the state of the Turing Machine
as a means of storing limited information. It extends the computational
power by encoding additional information into the states, thereby
reducing the need for external storage like a tape.

23. Formally define a Turing Machine (TM).


Answer: A Turing Machine is a 7-tuple (Q, Σ, Γ, δ, q0, B, F), where:
• Q: Set of states

• Σ: Input alphabet

• Γ: Tape alphabet (includes Σ and blank symbol B)

• δ: Transition function (Q × Γ -> Q × Γ × {L, R})

• q0: Initial state

• B: Blank symbol

• F: Set of final states

5
24. Turing recognizable languages are closed under union and
complementation – Explain.
Answer:
• Union: If two languages L1 and L2 are Turing recognizable, a Turing

Machine can be constructed to run both machines for L1 and L2 in parallel,


accepting if either accepts.
• Complementation: Turing recognizable languages are not necessarily

closed under complementation, as a language being recognizable does


not guarantee its complement is also recognizable.

25. Compare between:


• NPDA vs DPDA:

o NPDA (Non-deterministic PDA) can handle non-determinism and

accepts more CFLs than DPDA.


o DPDA (Deterministic PDA) is strictly deterministic and can only accept

a subset of CFLs.
• Undecidable vs Decidable Problems:

o Decidable problems have an algorithm that always halts and provides

a solution.
o Undecidable problems cannot have an algorithm that halts for all

inputs (e.g., Halting Problem).


• CFG vs RG:

o CFG (Context-Free Grammar) generates CFLs and is more expressive

than RG.
o RG (Regular Grammar) generates RLs and is less expressive but easier

to parse.
• CFL vs RL vs CSL:

o CFL (Context-Free Languages) are generated by CFGs and accepted by

PDAs.
o RL (Regular Languages) are generated by RGs and accepted by FAs.

o CSL (Context-Sensitive Languages) are generated by Context-Sensitive

Grammars and accepted by Linear Bounded Automata (LBA).

6
4. Consider a grammar with the rules: S → aSb | SS | λ. Draw the
leftmost derivation tree for the string aababbabab.
o Answer:
Leftmost Derivation:
o S → aSb
o → aaSbb
o → aaSbabb
o → aaSSbabb
o → aaSbSbabb
o → aaabSbSbabb
o → aababbabab
o Derivation Tree:
o S
o / \
o a b
o S
o / \
o a S
o / \
o S b
o / \
o S b
o / \
o a b
o
o 5. Consider a grammar with the rules: S → AB; A → aA | λ; B → bbB
| λ. Draw the leftmost derivation tree for the string aaabbbbbbb.
o Answer:
Leftmost Derivation:
o S → AB
o → ABBB
o → aABBB
o → aaABBB
o → aaaABBB
o → aaaBBB
7
o → aaaBbbBB
o → aaaBbbbBB
o → aaaBbbbbB
o → aaaBbbbbbb
o → aaabbbbbbb
o Derivation Tree:
o S
o /\
o A B
o / \
o aA B
o / \
o aA B
o / \
o aA B
o / \
o λ B
o / \
o bb B
o / \
o bb B
o / \
o bb λ
o
o 6. Consider a grammar with the productions: G: S → aSbb | λ; S1 →
bSa. Find the language generated by this grammar.
o Answer:
o The production S → aSbb | λ generates strings of the form an bbn,
where n ≥ 0.
o The production S1 → bSa introduces additional b and a at the
beginning and end, respectively.
o Combining both, the language generated by the grammar is:
L = { b an bbn a | n ≥ 0 }
o

8
o 7. The transition table of a DFA is shown in Figure 2. Compute step
by step, the acceptance (or rejection) of the string 01001011.
o Answer:
o Transition Table:
o δ(q, 0) → q1
o δ(q, 1) → q2
o Step-by-Step:
o Start state: q0
o Input: 0 → δ(q0, 0) = q1
o Input: 1 → δ(q1, 1) = q2
o Input: 0 → δ(q2, 0) = q2
o Input: 0 → δ(q2, 0) = q2
o Input: 1 → δ(q2, 1) = q2
o Input: 0 → δ(q2, 0) = q2
o Input: 1 → δ(q2, 1) = q2
o Input: 1 → δ(q2, 1) = q2
o Final State: q2 (Accepting State)
Result: String 01001011 is accepted.
o
o 8. Design a DFA that accepts all strings of 0’s and 1’s, that either
begins or ends (or both) with 01.
o Answer:
o DFA Design:
States:
o q0: Start state
o q1: Transition after seeing 0
o q2: Accepting state after seeing 01
o q3: Other transitions
o Transitions:
o δ(q0, 0) → q1
o δ(q1, 1) → q2
o δ(q2, 0) → q2
o δ(q2, 1) → q2
o

9
o 9. Design a DFA that accepts all strings of 0’s and 1’s, that either
begins or ends (or both) with 00.
o Answer:
Similar to Question 8 but modified for "00."
Transitions:
o δ(q0, 0) → q1
o δ(q1, 0) → q2
o δ(q2, 0) → q2
o δ(q2, 1) → q2
o
o 10. Create an NFA for accepting decimal numbers characterized by:
o Answer:
o The NFA will include:
o An optional + or - at the start.
o A sequence of digits.
o An optional decimal point followed by digits.
o States and Transitions:
o q0 → (+, -) → q1
o q1 → (digit) → q2
o q2 → (digit) → q2
o q2 → (.) → q3
o q3 → (digit) → q4
o q4 → (digit) → q4
o
o 11. Convert the NFA given in Figure 3, to the equivalent DFA using
subset construction method.
o Answer:
Subset Construction Steps:
o Start with the ε-closure of the start state.
o Compute transitions for subsets of states for each input.
o Mark states containing final NFA states as final DFA states.
o Let me know if you'd like this in tabular form!
o

10
14. Consider the Grammar X → X+X | X*X | X | a. Draw two different leftmost
derivation trees of the string a*a+a
Answer:
Leftmost Derivation 1:
X → X+X
→ X*X + X
→ a*X + X
→ a*a + X
→ a*a + a
Leftmost Derivation Tree 1:
X
/\
X X
/\ \
X X a
| |
a a
Leftmost Derivation 2:
X → X*X
→X+X*X
→a+X*X
→a+a*X
→a+a*a
Leftmost Derivation Tree 2:
X
/\
X X
| /\
a X X
| |
a a

11
15. Design a FA from the given regular expression 10 + (0 + 11)0*1.
Answer:
• Simplify the Regular Expression: The expression accepts strings starting

with 10, or a single 0, or strings starting with 11 followed by any number of


0s ending with 1.
• Design DFA:

o Start state transitions:

▪ 10 leads to accepting state.

▪ 0 leads to acceptance directly.

▪ 11 transitions to a loop for 0s, ending with 1.

DFA construction is best drawn visually, but I can describe transitions in text.

16. Construct the FA for regular expression 0*1 + 10.


Answer:
• Simplify the Expression: The expression accepts strings with zero or more

0s followed by a 1 or exactly 10.


• DFA Construction Steps:

1. Start in state q0.


2. On 0, loop in q0 for 0*.
3. On 1, move to q1 (accepting state).
4. From q0, on 1, transition to state q2.
5. In q2, accept only if the next input is 0.

17. Construct a minimum state automaton equivalent to the transition


diagram given in Figure 5.
Answer:
• To minimize, follow these steps:

1. Identify equivalent states by partitioning based on acceptance.


2. Merge states that behave identically for all inputs.
3. Reconstruct the DFA with merged states.
I’ll provide a text-based explanation or can redraw the diagram if needed.

12
18. Eliminate left recursion from the grammar: A → Abd | Aa | λ; B → Be | b.
Answer:
• Eliminate left recursion from A:

• A → Abd | Aa | λ

• Rewrite as:

• A → AbdA'

• A' → dA' | λ

• Eliminate left recursion from B:

• B → Be | b

• Rewrite as:

• B → bB'

• B' → eB' | λ

19. Eliminate left recursion from the grammar: S → aS | a; X → aX | a | λ.


Answer:
• Eliminate left recursion from S:

• S → aS | a

• Rewrite as:

• S → aS'

• S' → S' | λ

• Eliminate left recursion from X:

• X → aX | a | λ

• Rewrite as:

• X → aX'

• X' → X' | λ

13
20. Prove that L = {anbn : n ≥ 0} is not regular using the pumping lemma.
Answer:
Pumping Lemma: If L is regular, there exists a pumping length p such that any
string s ∈ L with length ≥ p can be split into xyz, satisfying:
1. |xy| ≤ p
2. |y| > 0
3. For all i ≥ 0, xy^iz ∈ L.
• Let s = apbp (choose n = p).

• Split s as xyz where x = a^i, y = a^j (with j > 0), and z = a^(p-i-j)b^p.

• Pump y: If i > 1, the number of as increases, so xy^2z becomes a^(p+j)b^p,

which is not in L.
• Conclusion: L is not regular.

21. Design a PDA to accept strings of the form 0n1n, n ≥ 0. Show the steps for
the string 011.
Answer:
PDA Construction:
• Push each 0 onto the stack.

• For each 1, pop one 0 from the stack.

• Accept if the stack is empty when all input is consumed.

Steps for 011:


1. Start in state q0.
2. Read 0, push onto stack.
3. Read 1, pop stack.
4. Read 1, stack is empty.
5. Move to accept state qf.

22. Consider the transition diagram of a PDA in Figure 5. Draw the


corresponding transition table. Convert this grammar to the equivalent PDA
and write down the transition rules.
Answer:
• Create a table showing transitions for stack operations (push, pop, or no-

op).
• Transition rules will directly correspond to the arcs in the diagram.

14
25. (a) Describe the Chomsky hierarchy of languages.
The Chomsky hierarchy includes:
1. Type 0: Recursively Enumerable Languages
o Generated by unrestricted grammars.

o Example: Palindrome strings with mismatched characters.

2. Type 1: Context-Sensitive Languages (CSL)


o Generated by context-sensitive grammars.

o Example: anbncna^n b^n c^n.

3. Type 2: Context-Free Languages (CFL)


o Generated by context-free grammars.

o Example: Balanced parentheses.

4. Type 3: Regular Languages


o Generated by regular grammars.

o Example: Strings with an even number of zeros.

25. (b) CFL Closure Properties


i. Union
If L1L_1 and L2L_2 are CFLs, L1∪L2L_1 \cup L_2 is also a CFL. Example:
L1={anbn}L_1 = \{a^n b^n \} and L2={bncn}L_2 = \{b^n c^n \}. Their union is
{anbn∪bncn}\{a^n b^n \cup b^n c^n\}.
ii. Concatenation
L1L2L_1 L_2 is a CFL if L1L_1 and L2L_2 are CFLs. Example:
L1={an}L_1 = \{a^n\} and L2={bn}L_2 = \{b^n\}. Their concatenation is
{anbn}\{a^n b^n\}.
iii. Kleene Closure
If LL is a CFL, then L∗L^* is also a CFL. Example:
L={ab}L = \{ab\}, then L∗={ε,ab,abab,...}L^* = \{ε, ab, abab, ...\}.

15
26. Context-Sensitive Grammar
(a) Definition
A context-sensitive grammar has rules of the form αAβ→αγβαAβ → αγβ, where
∣α∣≤∣γ∣|α| ≤ |γ|.
(b) Grammar for anbncna^n b^n c^n:
Rules:
1. S→aSBCS → aSBC
2. BC→CBBC → CB
3. CB→εCB → ε.
(c) Derivation for a2b2c2a^2b^2c^2:
1. S→aSBC→aaSBCBC→aaBCBCBC→aabCBCBC→aabbCCBC→aabbcBC→aabb
ccS → aSBC → aaSBCBC → aaBCBCBC → aabCBCBC → aabbCCBC →
aabbcBC → aabbcc.

27. Diagonalization Language


(a) Definition
The diagonalization language D={w∣w∉L(Mw)}D = \{ w \mid w \notin L(M_w) \}
ensures no Turing Machine MwM_w can decide DD.
(b) Proof
If DD were recursively enumerable, a Turing Machine would both accept and
reject ww, contradicting the definition of DD.

28. Turing Machine with Storage in State


For (01∗+10∗)(01^* + 10^*):
Transition Table:
State Input Write Move New State
q0q_0 00 XX RR q1q_1
q1q_1 11 11 RR q1q_1
q1q_1 εε εε RR Accept
Steps to Accept 100100:
1. Start at q0q_0, read 11, move to q1q_1.
2. Read 00, remain in q1q_1.
3. Accept when tape ends.
16
29. Context-Free Grammar S→aSa∣bSb∣cS → aSa | bSb | c
(a) GNF Form:
1. S→c∣aS∣bSS → c | aS | bS.
(b) Parse Tree for abaaacaaabaabaaacaaaba:
• Root: SS

• Expand using S→aSaS → aSa, S→bSbS → bSb, and S→cS → c.

(c) PDA Transition Rules:


1. Push aa and bb for every input.
2. Pop stack when cc is encountered.

30. NPDA and DPDA


• NPDA: Non-deterministic PDA can have multiple transitions for the same

input.
• DPDA: Deterministic PDA has only one possible transition per input.

• Difference: NPDA can recognize languages like {anbncn}\{a^n b^n c^n\},

which DPDA cannot.

31. Expressive Power of NPDA vs DPDA


• Not the Same: NPDA recognizes all CFLs, but DPDA cannot recognize

inherently ambiguous languages.

32. Regular Language Closure Properties


Union
If L1L_1 and L2L_2 are regular, L1∪L2L_1 \cup L_2 is regular using an NFA that
combines the two.
Intersection
If L1L_1 and L2L_2 are regular, L1∩L2L_1 ∩ L_2 is regular using a product
automaton.

17
33. Types of Turing Machines
1. Deterministic Turing Machine (DTM)
2. Non-Deterministic Turing Machine (NDTM)
3. Multi-Tape Turing Machine
4. Oracle Turing Machine
5. Universal Turing Machine

34. Importance of Oracle Turing Machine


It extends the computational power of a Turing Machine by allowing it to solve
problems in higher complexity classes (e.g., NP problems).

35. Closure Properties of Turing Recognizable Languages


• Union: Combine the Turing Machines of two languages using non-

determinism.
• Complementation: Closure under complementation is not guaranteed for

recognizable languages.

18
1. Definition of Turing Machine:
A Turing machine is a mathematical model of computation consisting of
the following tuples:
M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M = (Q, \Sigma, \Gamma, \delta, q_0,
q_{accept}, q_{reject})
o QQ: Finite set of states

o Σ\Sigma: Input alphabet (does not include the blank symbol)

o Γ\Gamma: Tape alphabet (Σ⊆Γ\Sigma \subseteq \Gamma)

o δ\delta: Transition function (δ:Q×Γ→Q×Γ×{L,R}\delta: Q \times

\Gamma \rightarrow Q \times \Gamma \times \{L, R\})


o q0q_0: Start state (q0∈Qq_0 \in Q)

o qacceptq_{accept}: Accept state (qaccept∈Qq_{accept} \in Q)

o qrejectq_{reject}: Reject state (qreject∈Q,qreject≠qacceptq_{reject}

\in Q, q_{reject} \neq q_{accept})


2. Instantaneous Description (ID):
An ID of a Turing machine is a snapshot of its current state, tape contents,
and head position.
Example: For a Turing machine in state qq, with tape ab_cab\_c (_\_
indicates a blank symbol), and head at cc, ID is (q,a b c‾)(q, a \, b \,
\underline{c}).
3. Turing Machine Construction:
a. Language L={anbn:n≥0}L = \{a^nb^n: n \geq 0\}: Use states to match
each aa with a corresponding bb by marking them.
b. Language L={anbncn:n≥0}L = \{a^nb^nc^n: n \geq 0\}: Use multiple
passes to mark a,b,ca, b, c sequentially.
c. Integer Addition and Subtraction: Represent numbers in unary and use
state transitions to simulate arithmetic operations.

Context-Free Grammar (CFG), Context-Free Language (CFL), and Push Down


Automata (PDA)
1. Definitions:
19
o CFG: A CFG is defined as G=(V,Σ,P,S)G = (V, \Sigma, P, S), where VV is a
finite set of variables, Σ\Sigma is the alphabet, PP is the set of
productions, and SS is the start symbol.
o CFL: A language generated by a CFG.

2. CFG Constructions:
a. L={anbn:n≥0}L = \{a^nb^n: n \geq 0\}:
S→aSb ∣ ϵS \rightarrow aSb \,|\, \epsilon
b. L={anb2n:n≥0}L = \{a^nb^{2n}: n \geq 0\}:
S→aSbb ∣ ϵS \rightarrow aSbb \,|\, \epsilon
c. L={anbmcm+n:m≥0,n≥0}L = \{a^nb^mc^{m+n}: m \geq 0, n \geq 0\}:
S→AB,A→aAb ∣ ϵ,B→cB ∣ ϵS \rightarrow AB, A \rightarrow aAb \,|\,
\epsilon, B \rightarrow cB \,|\, \epsilon
d. L={ambm+ncn:m≥0,n≥0}L = \{a^mb^{m+n}c^n: m \geq 0, n \geq 0\}:
S→aSb ∣ B,B→bBc ∣ ϵS \rightarrow aSb \,|\, B, B \rightarrow bBc \,|\,
\epsilon
e. L={am+nbmcn:m≥0,n≥0}L = \{a^{m+n}b^mc^n: m \geq 0, n \geq 0\}:
S→aSb ∣ aSc ∣ ϵS \rightarrow aSb \,|\, aSc \,|\, \epsilon
f. L={wcwR:w∈{a,b}∗}L = \{wcw^R: w \in \{a, b\}^*\}:
S→aSa ∣ bSb ∣ cS \rightarrow aSa \,|\, bSb \,|\, c
g. L={wwR:w∈{a,b}∗}L = \{ww^R: w \in \{a, b\}^*\}:
S→aSa ∣ bSb ∣ ϵS \rightarrow aSa \,|\, bSb \,|\, \epsilon
3. Closure Properties of CFLs:
o CFLs are closed under union, concatenation, and Kleene closure.

Proofs involve constructing new CFGs.


o CFLs are not closed under intersection or complementation.

4. Ambiguous Grammar:
A grammar is ambiguous if there exists a string with two or more distinct
parse trees.
Example: S→SS ∣ aS \rightarrow SS \,|\, a.
Inherently CFL: A language for which no unambiguous CFG exists. Example:
L={anbmcm:n,m≥0}L = \{a^nb^mc^m: n, m \geq 0\}.

5. Derivations:
o Leftmost Derivation: Replacing the leftmost variable in each step.

o Rightmost Derivation: Replacing the rightmost variable in each step.

20
Example Grammar:
E→E+E ∣ E−E ∣ a ∣ bE \rightarrow E + E \,|\, E - E \,|\, a \,|\, b
For input a−b+aa - b + a, draw both leftmost and rightmost derivation trees.
6. CNF and GNF:
o CNF: All productions are of the form A→BCA \rightarrow BC or A→aA

\rightarrow a.
o GNF: All productions are of the form A→aαA \rightarrow a\alpha,

where α\alpha is a string of variables.


Rules to convert CFGs to CNF/GNF involve removing ϵ\epsilon-productions, unit
productions, and simplifying rules.
7. PDA Definition:
A PDA is M=(Q,Σ,Γ,δ,q0,Z0,F)M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F),
where Γ\Gamma is the stack alphabet and Z0Z_0 is the initial stack symbol.
The associated data structure is a stack.
8. Deterministic and Non-deterministic PDA:
o DPDA has at most one move for each configuration.

o NPDA may have multiple moves.

Their expressive powers are not the same. NPDA can recognize all
CFLs, but DPDA cannot.
9. PDA Constructions:
a. L={anbn:n≥0}L = \{a^nb^n: n \geq 0\}: Push aa onto the stack, pop for
bb.
b. L={anb2n:n≥0}L = \{a^nb^{2n}: n \geq 0\}: Push aa, pop for every two
bb.
c. L={anbmcm+n:m,n≥0}L = \{a^nb^mc^{m+n}: m, n \geq 0\}: Use stack to
count aa and bb, ensuring counts align with cc.
d. L={ambm+ncn:m,n≥0}L = \{a^mb^{m+n}c^n: m, n \geq 0\}: Track mm
and nn transitions using the stack.
e. L={am+nbmcn:m,n≥0}L = \{a^{m+n}b^mc^n: m, n \geq 0\}: Similar stack-
based logic for sequential symbols.
f. L={wcwR:w∈{a,b}∗}L = \{wcw^R: w \in \{a, b\}^*\}: Push ww onto the
stack, match wRw^R after cc.
g. L={wwR:w∈{a,b}∗}L = \{ww^R: w \in \{a, b\}^*\}: Push ww and match
wRw^R directly.

21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy