Professional Documents
Culture Documents
Term Paper On
Course Title: Formal System
Course Code: CSE 904
Submitted To Submitted By
Supriya Sarker Sanzida Islam
Lecturer REG: WUB03/18/42/2610
Department of CSE Batch: 42/A
World University of Bangladesh Department of CSE
World University of Bangladesh
Answer to the question no: 01(a)
i.
Input alphabet, Σ={a, b}
L = {ab, ba, aabb,baaa,………….}
The required DFA is-
a b
a q2
q0 q1
b b
a
a
q3 q2
b
Answer to the question no: 01(b)
ii.
Input alphabet, Σ={a, b}
Language L = {ε, ab, abab, bbbb, ...}
The required DFA is-
b b
a b
q0 q0 q0
a
a
q0
Answer to the question no: 01(a)
iii.
1 0,1
1
0 0 0
q0 q1 q2 q3
Here,
S = sentence,
VP = verb phrase,
NP = noun phrase,
PP = prepositional phrase,
DT=determiner,
Vi=intransitive verb,
Vt=transitive verb,
NN=noun,
IN=preposition
Parse tree
NP VP
DT NN Vi
A parse of the sentence " the man sleeps" is: S =>NP VP => DT N VP=> the N VP => the man
VP => the man Vi => the man sleeps.
i.
P = {S → AB | C, A → aAb | ab, B → cBd | cd, C → aCd | aD, D → bDc | bc}
A grammar for P is
S → AB | C
A → aAb | ab
B → cBd | cd
C → aCd | aDd
D → bDc | bc
The string aa bb cc dd has two left most derivation and and the two parse tree:
Left most derivation
S ⇒ AB
→ aAbB
→ aabbB
→ aabb CBd
→ aabb CCdd
Parse tree 01
A B
S S S S S S
S S S S
a d
a d
b c
b c
Right most derivation:
S ⇒ AB
R.M.D
→ AcBd
→ Accdd
→ aAb ccdd
→ aabb ccdd
Yes, the grammar is ambiguous.
ii.
S → aSbS|bSaS|∈
For grammar to be ambiguous, there should be more than one parse tree for same string. Above
grammar can be written as
S → aSbS
S → bSaS
S→∈
Let’s generate a string 'abab'. So, now parse tree for 'abab'.
Left most derivative parse tree 01
S → aSbS
S → a∈bS
S → a∈baSbS
S → a∈ba∈b∈
S → abab
S
a S b S
∈ a S b S
∈ ∈
Parse Tree 01
Left most derivative parse tree 02
S → aSbS
S → abSaSbS
S → ab∈aSbS
S → ab∈a∈bS
S → ab∈a∈b∈
S → abab
S
a S b S
b S a S ∈
∈ ∈
Parse Tree 02
So there are more than 1 parse tree for same string, that means grammar is ambiguous.
an input tape,
a control unit, and
a stack with infinite size.
Answer to the question no: 3(b)
0, ∈→0 1, 0→∈
Proof:
Assume A is regular and pumping length = P
S = 0p10p1 [Let S = 0000000100000001 where P=7]
S = xyz and |y| ≥ 1 and |xy| ≤ p, so y contains only 0s.
xyi z ∉ A. Here, we choose i = 2. xy2 z = xyyz = 0p+|y|10p, but |y|≠ 0
so this string is not in A, contradicting the pumping lemma. Thus, A is not regular.
Answer to the question no: 4(a)
Convert the given NFA to DFA.
0 0,1 0 0,1
q0 1 q1 q2
1
For the given transition diagram we will first construct the transition table.
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}
0 1 0
[q0]
1 [q1] [q2]
0 1
[q1, q2]
0,1
p
t
q
s
r
Step 2:
Consider all the un-ticked areas of step1
For an input(either a or b) for each un-ticked state, see the intermediate state For the area (r,t):
(r,a) => {r} and (t,a) =>s
So, here the intermediate state is ‘s’
Now check if {r,s} is ticked in step1.
If yes, tick {r,t} as well.
Similarly, {q,u} and {r,q} are also ticked
Step3:
Continue step2 until all states have been processed. Once no more can be ticked, algorithm
terminates.
Hence, here {s,u} is also ticked.
Final table now becomes
State u p t q s r
p
t
q
s
r
Step 4:
Check the spaces which are still un-ticked and such states can be merged together.
In the final minimized DFA, q-s are the new states and p-t are the new states