Beruflich Dokumente
Kultur Dokumente
[0+(0+1)(1+00)*01]*(0+1)(1+00)*
A -> 0A | 0B | 1B
B -> 1B | 0C | e
C -> 0B | 1A
Draw a finite state machine that accepts the complement of the language accepted
by the non-deterministic machine below:
answer:
Determine and prove for each set below whether it is Regular or not. Be careful.
a. The set of all strings in which every third symbol is the same as the first
symbol in the string.
c. The set of strings where each string has an equal number of 0?s and 1?s,
and every prefix of the string has at most one more 0 than 1, and at most
one more 1 than 0.
Determine whether Regular sets are closed under each of the operations below.
Prove your answers by an explanation and/or example or counterexample.
a. Even(L) is the set of all strings x in L such that |x| is even.
5 NPDAs
a. {1n0n | n>0}
b. {0n12n | n>=0}
6 CFGs
7 AMBIGUITY
Explain why the grammar below is ambiguous.
S -> 0A | 1B
A -> 0AA | 1S | 1
B -> 1BB | 0S | 0
The grammar is ambiguous because we can find strings which have multiple derivations:
S S
0A 0A
0 0AA 0 0AA
00 1S 1 00 1 1S
001 1B 1 0011 0A
0011 0 1 00110 1
8 Converting to Normal Form
S -> e | A0 | 0 | AS1 | B0 | A1 | 1A
A -> A0 | 0
B -> B1 | BC
C -> CB | CA | 1B
S1 -> B0 | 1A
NOTE: We did not need to create a new start state because the given one did not
appear in the right side of any rule.
b. Convert the following grammar into an equivalent one with no unit productions
and no useless symbols.
S -> A | CB
A -> C | D
B -> 1B | 1
C -> 0C | 0
D -> 2D | 2
Converts to
S -> 0C | 0 | 2D | 2 | CB
A -> C | D
B -> 1B | 1
C -> 0C | 0
D -> 2D | 2