0% found this document useful (0 votes)
31 views

Write CFG For The Given DFA

it explain toc

Uploaded by

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

Write CFG For The Given DFA

it explain toc

Uploaded by

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

1.

Write CFG for the given DFA


The DFA in the image has states {1, 2, 3, 4, 5} with transitions on 'a' and 'b'.
Let's write the corresponding CFG.

DFA Transitions:
State 1:
on 'a' -> State 2
on 'b' -> State 3
State 2:
on 'a' -> State 5
on 'b' -> State 4
State 3:
on 'a' -> State 1
on 'b' -> State 4
State 4:
on 'a' -> State 3
on 'b' -> State 5
State 5:
on 'a' -> State 2
on 'b' -> State 5
CFG Construction:
Non-terminals: {S, A, B, C, D}
Start symbol: S
Terminals: {a, b}
Production rules:
coq
Copy
S -> aA | bB
A -> aD | bC
B -> aS | bC
C -> aB | bD
D -> aA | bD
2. Write CFG for Palindromes over {a, b}
A palindrome reads the same forward and backward.

CFG Construction:
Non-terminals: {S}
Start symbol: S
Terminals: {a, b}
Production rules:
Copy
S -> aSa | bSb | a | b | ε
3. CFG for strings not containing "bbb" over {a, b}
We've discussed this earlier. Here's the CFG:

CFG Construction:
Non-terminals: {S, A, B}
Start symbol: S
Terminals: {a, b}
Production rules:
Copy
S -> AS | BS | ε
A -> a
B -> bA | bB
4. CFG for (a + b)* (abb + ababa) (a + b)*
This represents strings with "abb" or "ababa" in the middle, surrounded by any
sequence of 'a's and 'b's.

CFG Construction:
Non-terminals: {S, X, Y, Z}
Start symbol: S
Terminals: {a, b}
Production rules:
Copy
S -> XSX | X
X -> aX | bX | Y | ε
Y -> abb | ababa
5. CFG for (a + b)*(a bbbd + (a + b)*ba)
This represents strings with "abbbd" or any sequence of 'a's and 'b's ending in
"ba".

CFG Construction:
Non-terminals: {S, X, Y, Z, W}
Start symbol: S
Terminals: {a, b, d}
Production rules:
coq
Copy
S -> XSX | X
X -> aX | bX | Y | W | ε
Y -> abbbd
W -> Zba
Z -> aZ | bZ | ε
These CFGs should address the tasks provided in your image.

You might also like