0% found this document useful (0 votes)
46 views10 pages

DFA for a's mod 2 and b's mod 3

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)
46 views10 pages

DFA for a's mod 2 and b's mod 3

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

DEPARTMENT OF AIML

ASSIGNMENT QUESTIONS
Course Name: Automata Theory & Compiler Design Course Code: AIM3202
1. Construct a DFA with minimum number of states, accepting all strings over {a,
b} such that the number of a’s is divisible by two and the number of b’s is
divisible by three.
2. Construct a DFA with minimum number of states, accepting all strings over {a,
b} such that the number of a’s is not divisible by two and the number of b’s is
divisible by three.
3. Construct a DFA with minimum number of states, accepting all strings over {a,
b} such that the number of a’s is divisible by three and the number of b’s is
divisible by two.
4. Draw a DFA which accepts all strings over {a, b} such that no string has three
consecutive occurrences of the letter b.
5. Draw a DFA which accepts all strings over {a, b} such that the set of string does
not contain abab as a substring.
6. Design a DFA to recognize all strings over {a,b} such that L={awa : w ϵ {a,b}*}.
7. Design a DFA to accept all strings over {a,b} such that L={aw1aaw2a : w1 , w2 ϵ
{a,b}* .
8. Design a DFA for Σ = {a, b} that can accept all strings with no more than three
a’s.
9. Find DFA for the following languages on Σ = {a, b}:
a. L = {w : |w| mod 3 = 0
b. L = {w : na(w) mod 3 > nb(w) mod 3}
10. Consider the set of strings on {0,1}. Design a DFA to accept all strings where
every 00 is followed immediately by a 1.
11. Draw a DFA for all binary strings divisible by 3.
12. Draw a DFA for all binary strings divisible by 2.
13. Suppose Σ = {0, 1, 2}. Draw a DFA for the language L = {w | the sum of digits in
w is divisible by 5}.
14. Draw a DFA for L = {0n1m | m ≥ 1 , n ≥ 0 ; (n + m) is divisible by 3}.
15. Suppose Σ = {a, b}. Find a DFA for the set of strings w such that the number of
occurrences of the substring ab in w equals the number of occurrences of the
substring ba in w.
16. Construct a DFA accepting all strings w over Σ = {0, 1} such that the number of
1’s in w is 3 mod 4.
17. Construct a DFA to accept all strings over Σ = {a, b} that ends in bb.
18. Design a DFA to accept all strings over Σ = {a, b} with even number of a’s and
even number of b’s.
19. Construct a DFA equivalent to the NFA defined by the regular expression
(0+1)∗00
Session: July – Nov 2025 V Semester
20. Design a DFA from the given NFA that accepts all strings over {a, b} that
contain substring “aba”.
21. Construct a DFA equivalent to the NFA accepting strings over {0,1} that end
with either 01 or 10.
22. Represent the following sets by regular expression:
a. {12n+1 | n>0
b. {The set of all strings over {0,1} which has at most two zeros.
c. {an | n is divisible by 2 or 3 or n=5}.
d. The set of all strings over {a, b} beginning and ending with a.
23. Construct a transition system corresponding to the following regular expressions:
a. (ab + c*)*b b. a + bb + bab*a
c. (ab + a)*(aa + b) d. (a*b + b*a)*a
24. Find the regular expressions representing the following sets. Then Construct the
equivalent NFA and convert that NFA into an equivalent DFA using the subset
construction method.
a. The set of all strings over {0,1} having at most one pair of 0’s or at most one
pair of 1’s.
b. The set of all strings over {a,b} in which the number of occurrences of a is
divisible by 3.
c. The set of all strings over {a,b} in which there are at least two occurrences
of b between any two occurrences of a.
d. The set of all strings over {a,b} with three consecutive b’s.
e. The set of all strings over {0,1} beginning with 00.
f. The set of all strings over {0,1} ending with 00 and beginning with 1.
25. Prove the following:
a. Arden’s theorem
b. (0*1*)* = (0 + 1)*
c. (ab)* ≠ (a*b*)
d. (r + s)* ≠ r* + s*
e. λ + 1*(011)*(1*(011)*)* = (1 + 011)*
26. Construct R.E. using Arden’s theorem from the following FA’s:
a.
a B
→q1 q1 q2
*q2 q3 q2
q3 φ φ
b.
0 1
→* q1 q2
q1
q2 q3 q2
q3 q1 q2
c.
Session: July – Nov 2025 V Semester
0 1
→*q1 q1 q2
→*q2 q3 q2
q3 q3 q3
d.
0 1
→*q1 q2 q3
q2 q4 q1
q3 q1 q4
q4 q4 q4

Session: July – Nov 2025 V Semester


e.
0 1
→*q1 q1 q1
f.
a b
→q1 q3 q2
q2 q2 q2
*q3 q3 q3
g.
0 1
→q1 q2 q2
*q2 q1 q1
h.
0 1
→q0 q1 q1
q1 φ φ
*q2 q1 q1

27. Construct a regular expression corresponding to the automata given below –

28. Construct the regular grammar for the following language.


a. The set of all strings over {0,1} having at most one pair of 0’s or at most one
pair of 1’s.
b. The set of all strings over {a,b} in which the number of occurrences of a is
divisible by 3.
c. The set of all strings over {a,b} in which there are at least two occurrences
of b between any two occurrences of a.
d. The set of all strings over {a,b} with three consecutive b’s.
e. The set of all strings over {0,1} beginning with 00.
f. The set of all strings over {0,1} ending with 00 and beginning with 1.
g. L={w01∣w∈{0,1}*}
h. L={xaby∣x,y∈{a,b}*}
i. L={aw∣w∈{a,b}*}
j. L={00,01,10,11}
k. L={ambnck∣m,n,k≥1}

Session: July – Nov 2025 V Semester


29. Construct the context free grammar for the following language.
a. L={w∣w=wR,w∈{a,b}*}
b. L={w∣w is a well-formed sequence of ( and )}
c. L={w∈{a,b}*∣ #a(w)>#b(w)}
d. L={ambn∣m is not equals n}
e. L={ambn∣m = n2}
f. L={ambncm∣m,n≥1}
g. L={ambm+ncn∣m,n≥1}

30. Consider the following grammar-


S → ABC
A→a
B→b
C→c

Consider a string w = abc.


Design all possible LMD and RMD.

Session: July – Nov 2025 V Semester


31. Consider the grammar-
S → bB / aA
A → b / bS / aAA
B → a / aS / bBB
For the string w = bbaababa, find-
1. Leftmost derivation
2. Rightmost derivation
3. Parse Tree
32. Consider the grammar-
S → A1B
A → 0A / ∈
B → 0B / 1B / ∈
For the string w = 00101, find-
1. Leftmost derivation
2. Rightmost derivation
3. Parse Tree
33. Consider the following grammar and eliminate left recursion-
A → ABd / Aa / a
B → Be / b
34. Consider the following grammar and eliminate left recursion-
E→E+E/ExE/a
35. Consider the following grammar and eliminate left recursion-
E→E+T/T
T→TxF/F
F → id
36. Consider the following grammar and eliminate left recursion-
S → (L) / a
L→L,S/S
37. Consider the following grammar and eliminate left recursion-
S → S0S1S / 01
38. Consider the following grammar and eliminate left recursion-
S→A
A → Ad / Ae / aB / ac
B → bBc / f
39. Do left factoring in the following grammar-

Session: July – Nov 2025 V Semester


S → iEtS / iEtSeS / a
E→b
40. Do left factoring in the following grammar-
A → aAB / aBc / aAc
41. Do left factoring in the following grammar-
S → bSSaaS / bSSaSb / bSb / a
42. Do left factoring in the following grammar-
S → a / ab / abc / abcd
43. Do left factoring in the following grammar-
S → aAd / aB
A → a / ab
B → ccd / ddc
44. Check whether the given grammar is ambiguous or not-
S → SS
S→a
S→b
45. Check whether the given grammar is ambiguous or not-
S→A/B
A → aAb / ab
B → abB / ∈
46. Check whether the given grammar is ambiguous or not-
S → AB / C
A → aAb / ab
B → cBd / cd
C → aCd / aDd
D → bDc / bc
47. Check whether the given grammar is ambiguous or not-
S → AB / aaB
A → a / Aa
B→b
48. Check whether the given grammar is ambiguous or not-
S → a / abSb / aAb
A → bS / aAAb
49. Convert the following ambiguous grammar into unambiguous grammar-

Session: July – Nov 2025 V Semester


R → R + R / R . R / R* / a / b
where * is kleen closure and . is concatenation.
50. Consider the given grammar-
E→E+T/T
T→FxT/F
F → id

Evaluate the following expression in accordance with the given grammar-


2+3x5x6+2
51. Consider the given grammar-
E→E+T/E–T/T
T→TxF/T÷F/F
F→G↑F/G
G → id

Evaluate the following expression in accordance with the given grammar-


2x1+4↑2↑1x1+3
52. Removal of Useless Symbols
T → xxY | xbX | xxT
X → xX
Y → xy | y
Z → xz
53. Remove the ε production from the CFG given below by preserving its meaning.
S → ABA
A → 0A | ε
B → 1B | ε
54. Removing Unit Productions:
S → 0X | 1Y | Z
X → 0S | 00
Y→1|X
Z → 01

55. Convert the given CFG to CNF. Consider the given grammar G:

Session: July – Nov 2025 V Semester


S → a | aA | B
A → aBB | ε
B → Aa | b

56. Convert the given CFG to GNF. Consider the given grammar G:
S → XB | AA
A → a | SA
B→b
X→a
57. Design a PDA for accepting a language {anb2n | n>=1}.
58. Design a PDA for accepting a language {0n1m0n | m, n>=1}.
59. Construct a PDA that accepts the language L over {0, 1} by empty stack which
accepts all the string of 0's and 1's in which a number of 0's are twice of
number of 1's.
60. Design NPDA for Palindrome strips.
61. Convert the following grammar to a PDA that accepts the same language.
S → 0S1 | A
A → 1A0 | S | ε

62. Construct PDA for the given CFG, and test whether 010000 is acceptable by this
PDA.
S → 0BB
B → 0S | 1S | 0

63. Draw a PDA for the CFG given below:


S → aSb
S→a|b|ε

64. Construct the PDA for the following language and then convert the resulting PDA
into its equivalent CFG.
a. L={w∣w=wR,w∈{a,b}*}
b. L={w∣w is a well-formed sequence of ( and )}
c. L={w∈{a,b}*∣ #a(w)>#b(w)}
d. L={ambn∣m is not equals n}
e. L={ambn∣m = n2}
f. L={ambncm∣m,n≥1}
g. L={ambm+ncn∣m,n≥1}

Session: July – Nov 2025 V Semester


Session: July – Nov 2025 V Semester

Common questions

Powered by AI

Minimizing states in DFA design is crucial to reducing complexity and ensuring efficient computation. Fewer states decrease memory usage, enhance processing speed and simplify testing by easing comprehension of machine behavior. State minimization often consolidates equivalent machinery into singular states without altering language acceptance, based on equivalence classes derived from indistinguishably leading states. This optimization makes automata succinct and manageable, especially when DFA models are used in pattern recognition or compiler design for real-time applications.

Converting a CFG to CNF involves these steps: 1) Remove null productions by substituting rules containing null-producing non-terminals. 2) Remove unit productions by substituting longer rules for unit rules. 3) Eliminate useless symbols. 4) Transform remaining productions so that each is either of form A → BC, where B and C are non-terminals, or A → a, where a is a terminal. Begin transformations by adjusting terminal combinations to new variables, then break down remaining rules iteratively to binary forms.

Left factoring a grammar resolves common prefixes by factoring them out. For S → iEtS / iEtSeS / a, notice the common prefix 'iEt'. Rewrite as S → iEtS', S' → eS / ε, and also S → a. Here, S starts with 'iEt', and non-terminal S' determines continuation with or without 'eS'. This transformation eliminates redundancy, making the grammar easier to parse by avoiding dynamic decision-making on common prefixes.

To construct a DFA where the number of 'a's and 'b's are both even, first define states to track the parity (even or odd) of 'a's and 'b's. Use four states: q0 (where both a's and b's are even), q1 (where a's are even, b's are odd), q2 (where a's are odd, b's are even), and q3 (where both are odd). Start at q0. From q0, an 'a' transitions to q2, 'b' transitions to q1. From q1, an 'a' transitions to q3, 'b' returns to q0. From q2, an 'a' returns to q0, 'b' transitions to q3. From q3, an 'a' transitions to q1, 'b' returns to q2. The accepting state is q0, where both counts are even.

Design a PDA using two stages. Stage1 involves reading two 0's for every 1, pushing one 0 onto the stack for input 0 and popping it with an input 1. Start with pushing a stack symbol to state 1 for each 0, shift to state 2 to pop a stack symbol for each 1 until reading completes. Change and clear the stack by popping for 0's until consumed. Accept if all stack 0's are matched to ensure equal 0's before and after 1's.

Convert an NFA to DFA using the subset construction method. First, create a start state representing the NFA's start state plus all ε-closure states. For each DFA state, for input symbol 'a', compute the set of NFA states reachable from any state in the current DFA state via 'a' including ε-transitions. Add new DFA state unless previously recorded. Repeat for all inputs and NFA states, marking DFA start and any NFA transitioning to NFA accept states as DFA accept states.

To design a DFA for strings that ends in 'bb', use a small number of states to track the suffix. Start from q0, the initial state, and move to q1 upon reading 'b'. Stay in q1 if another 'b' is read, moving finally to an accepting state q2. Read 'a' at q1 returns to q0. Read 'a' or 'b' at q0 also keeps the current state. Read 'a' at q2 returns to q0, maintaining q2 for 'b'. The DFA uses these transitions to ensure 'bb' is at string's end, accepting only if ending at q2.

To eliminate left recursion in the grammar E → E + E / E x E / a, introduce new non-terminal: E' to handle recursion. Rewrite the grammar as follows: E → aE', E' → +EE' / xEE' / ε. E generates an atomic expression with E', which optionally applies operations recursively. This eliminates direct left recursion by transforming the recursive elements to a sequence of right-associated elements with optional continuation.

To determine ambiguity, test if a string exhibits more than one distinct derivation tree. For grammar S → SS | a | b, consider string 'aa': Either derive via S → SS → aa (two S→a); or S → SS → SSS → aSS → aaS → aaa. Both produce 'aa' differently. This multiple distinct parse path indicates ambiguity since parse trees show differing branch structures for identical strings.

Design a DFA for strings where each '00' is followed by '1'. Use these states: q0 (no '00' seen), q1 (recently saw '0'), q2 (saw '00'), and accepting q3 (completed '001'). From q0 see a '0', move to q1. Seeing '0' then '1' at q1 leads to q3. '0' directly at q1 transitions to q2, requiring a '1' next to go to q3, otherwise reset to q0 on '00' not followed by '1'. This structure ensures all '00's are validated by following '1's on path to q3.

You might also like