TOC Assignment
TOC Assignment
COMPUTATION
E → pPq | qQp
P → pP | qP | q | p
Q → qQ | pQ | p | q
E) e0 → xe1 | be4
e0 → xe2 | be2
e2 → xe2 | be3
e3 → be3 | ae2 | ε
e4 → ae5 | be5
e5 → be5 | ae6
e6 → ae6 | be5 | ε
2) .
A) The following regular expression generates all strings that does not begin with 11
A = (00,0,01,000,010….)
B = (11,111,1101,110…)
RE = 0 ( 0 + 1 ) * + 10 ( 0 + 1 ) * + 1 + ε
B) The following regular expression generates all strings in which every appearance of 0 is
followed by a 1
A = (01,0101,010101,11,1101….)
B = (00,010,0100,01010…..)
RE = ( 1 * (01) * 1 * ) *
3) .
A) ε = { 1,2,3,4,5,6,7,8,9,0 }
S → MUV
U→N|ε
V→VV|N
N → M | 3 | 4 | 5 | 6 | 7 | 8| 9 | 0
M→1|2
M U V
2 N V V
M N V V
1 4 V V V V
V N V V V
N M N V V
7 1 8 N N
5 8
B) The above stated grammar is ambiguous, due to the following string “21471858” has more
than one parse tree, which is shown below
Tree 1
M U V
2 N V V
M V V V V
1 N V V V V V
4 N V V V V
7 N N N N
1 8 5 8
Tree 2
M U V
2 N V V
M V V V V
1 V V V V V V
V V V V N N
N N N N 5 8
4 7 1 8
C) The followings steps are to be followed for the convertion of CFG to Chomsky Normal Form.
S → M U V | MV
U→N
V → VV | N
N→M|3|4|5|6|7|8|9|0
M→1|2
S → MUV
U→N|
V → VV | N
N→M|3|4|5|6|7|8|9|0
M→1|2
Step 2: Eliminate Variable Unit Productions
S → M U V | MV
U→N|1|2|3|4|5|6|7|8|9|0
V → VV | 1 | 2 |3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
M→1|2
S → DU | MV
D → MV
V → VV | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
M→1|2
S → M U V | MV
D → MV
U→1|2|3|4|5|6|7|8|9|0
V → VV | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
M→1|2
4) .
Step 2: Read the string. If the entered characters are not empty it pushes the character to the
stack, if we enter a empty value it reaches the next stage.
Step 3: It again reads until the character is empty or founded another character. If again the
same ‘s’ is entered it pops elements from stack. If found end of string it also pops that and
accepts the string.
Example: E = x x y y x x
Start → read
↓
read x
↓
read x
↓
read y
↓
read y
↓
read x
↓
read x
↓
read (found empty)
↓
read again each character and pop every single element
So, all the elements gets popped and simultaneously the same character ‘s’ is deleted
each iteration. So, in the reverse order the string is same. Thus, it accepts a palindrome
string.
This string is not a palindrome. As a result, it accepts the string first, and then when popping the
elements, it accepts the string in reverse.
5) .
A) Initial State: A
Goal State: G
B)
C) We consider two sides of the tape. The numbers before the $ sign are on one side, while the
numbers after the $ sign are on the other. We add 1 to the integer on the left side (Binary
addition) while subtracting 1 from the right side (Binary Subtraction). We continue this
procedure until all of the numbers on the right side of the $ symbol are 0, at which point the
0's and the $ sign are replaced with.