Quiz 2
Quiz 2
Quiz 2
SCaD
Machine #1:
Alphabet: {a, b}
Start state: q0
Transition function:
δ(q0, a) = q0
δ(q0, b) = q1
δ(q1, a) = q0
δ(q1, b) = q1
b>
q0 q1
Machine #2:
Alphabet: {a, b}
Start state: q0
Transition function:
δ(q0, a) = q1
δ(q0, b) = q0
δ(q1, a) = q2
δ(q1, b) = q0
δ(q2, a) = q1
δ(q2, b) = q
b>
Question 2:
Show the equivalent DFA for the above NFA:
Closure:
ε-closure(s1) = {s1}
ε-closure(s2) = {s2}
ε-closure(s3) = {s3}
Transition Table:
DFA state a b
s1 s1 s1, s2, s3
s1,s2, s3 s1, s2, s3 s1, s2, s3
s2 s3
s3
Initial State:
Transitions:
From {s1}:
On 'a', go to {s1}.
From {s2}:
On 'a', go to {s3}.
On 'b', go to ∅ .
From {s3}:
On 'a' or 'b', go to ∅ .
Final States:
Question 3:
[ ] { std::cout « “5”;}
. { std::cout « “6”;}
Acadccafcc
Solution:
∑ Assuming that whitespace is not significant in language:
∑ If we assume that whitespace is significant in the language and should be tokenized separately
Then output will be “15453”