Beruflich Dokumente
Kultur Dokumente
L = { w | w {0, 1}* and the number of 0's in w is divisible by 2 and the number of 1's
in w is divisible by 3} .
1 1
0 0 0 0 0 0
1 1
2. (5 points)
Draw a state diagram for an NFA over {0, 1}that accepts strings that consist of either
For example, acceptable strings would include 01, 010101, and 010010.
0
0 1
0 1 0
0
2
REGULAR EXPRESSIONS and REGULAR LANGUAGES
Let A = (Q, , , , {qf}} be an NFA such that there are no transitions into q0 and no
transitions out of qf. Decsribe the language accepted by each of the following
modifications of A, in terms of L = L(A):
(b) The automaton constructed from A by adding an -transition from q0 to every state
reachable from q0 (along a path whose labels may include symbols from as well as ).
(c) The automaton constructed from A by adding an -transition to qf from every state
that can reach qf along some path.
L(L S)*, where S is the set of suffixes of string in L. If there are states in A that cannot
be reached from q0 but which have a path to qf, then the strings generated along those
paths must be included in S.
4. (10 points) Write a regular expression for the set of all strings of 0's and 1's such that
every pair of adjacent 0's appears before every pair of adjacent 1's.
(10+0)*(ε+1)(01+1)*(ε+0)
3
CONTEXT-FREE LANGUAGES
5. (15 points) Recall that a derivation for a CFG G is a sequence of substitutions using
the rules of the grammar, ending with a string in the language. We will call the number
of substitutions the length of the derivation.
Example: if, for some grammar, we had the derivation S 0S1 00S11 00211, the
length of the derivation is 3.
Let G be any context-free grammar. Prove that for n > 0, the number of strings that have
a derivation in G of length n or less is finite.
Let b be the maximum number of symbols on the right-hand side of a rule. Then any step
of a derivation increases the number of symbols by b – 1, since 1 symbol is replaced by b
symbols. For example, if R 0A11 is a rule and in a derivation we arrive at 00BR01C,
then the next step could be 00B0A1101C, which is an increase of 3 symbols. In general,
the number of symbols at step n of a derivation can be no more than max = 1 + n(b – 1),
where the starting symbol is step 0. If m = ||, then the possible number of strings that
could result from an n-step derivation is maxm, which is a finite number.
6. (15 points) Use the Pumping Lemma to show that the following language is not
regular. We have laid out the proof for you, so use this form and fill in the blank spots.
L = {wcn | w (a, b}* and (the number of a's in w) = n or (the number of b's in w) = n}
Clearly, w belongs to L, because the number of c's equals the number of a's_______.
Since |xy| p, y must consist entirely of a's. In that case, xy2z would not be in L, since
the number of c's is not correct.
7. (15 points) Show that the following language is undecidable by reduction from ATM:
LTM = {M, w | Turing machine M, when given w as input, tries to move its head
left from the leftmost tape cell, at some point in the computation}
Assume for the sake if a contradiction that TM R decides LTM. Construct TM S to decide
ATM as follows:
TM S decides ATM because M' only moves left from the leftmost tape cell when M
accepts w. S never attempts that move during the course of the simulation because we
put the $ in place so we could intercept such moves if made by M.
NP-COMPLETENESS
8. (20 points) We define the class coNP to be the languages that are the complements of
languages in NP. As Sipser points out, we don’t know whether coNP is different from
NP.
BTW, it is thought that coNP is different from both P and NP, and that no NP-complete
problem is in coNP.