Sie sind auf Seite 1von 4

Handout #61 CS103

June 2, 2010 Robert Plummer

Practice Final Solutions


FINITE AUTOMATA

1. (5 points) Let L be the following language:

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} .

Draw a state diagram for a DFA whose language is L.

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

01 followed by 01 repeated zero or more times or


010 followed by 010 repeated zero or more times.

For example, acceptable strings would include 01, 010101, and 010010.
0
0 1

 0 1 0

0
2
REGULAR EXPRESSIONS and REGULAR LANGUAGES

3. (15 points) There are three parts to this question.

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):

(a) The automaton constructed from A by adding an -transition from qf to q0.

LL*, which is L+.

(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 ).

The set of suffixes of strings in L.

(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)*(10  1)*

Here is another possibility:

(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}

The proof is by contradiction. Assume that L is ___regular_______. Let p be the


pumping length for L as given by the pumping lemma.

Consider the string w = ___apcp__________.

Clearly, w belongs to L, because the number of c's equals the number of a's_______.

By the Pumping Lemma, we can write w = xyz where for each i  0,


xyiz  L, |y| > 0, ,and |xy|  p.

(the rest of the proof goes here)

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.

Thus, we have a contradiction, and L is not regular.


4
TURING MACHINES/UNDECIDABILITY

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:

S = "On input M, w:


1. Convert M to M', where M' first moves its input over one cell to the right and
writes new symbol $ on the leftmost tape cell. Then M' simulates M on the input. If M'
ever sees $, then M' moves its head one cell right and remains in the same state. If M
accepts, M' moves its head all the way to the left, and then (tries to) move left off the
leftmost tape cell.
2. Run R, the decider for LTM, on M', w.
3. If R accepts, then accept. If R rejects, then reject.

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.

Prove that if P = NP, then NP = coNP.

We showed in PS9 that P is closed under complementation. So if NP is the same as P,


then NP is also closed under complementation, i.e., NP = coNP.

BTW, it is thought that coNP is different from both P and NP, and that no NP-complete
problem is in coNP.

Das könnte Ihnen auch gefallen