CSC 320 Fall 2013: Assignment #3 Due at beginning of class, Fri

advertisement
CSC 320 Fall 2013: Assignment #3
Due at beginning of class, Fri. Oct. 25
Draw boxes for your marks. Place a 0 in the corresponding box for any questions you omit.
Question
1
2
3
4
5
6
Marks
1.
The purpose of this question is to prove that the pumping lemma is a necessary but not a
sufficient condition for a language to be regular. Consider the language
L 1 = {u u R v : u, v ∈ {0, 1}+ }
(u and v are strings made up of 0’s and 1’s of length at least one).
(a)
[2] How many strings are in in L 1 with length at most 6? Justify your answer by telling
me the choices for a minimal prefix u and the number of choices left for v in each case.
(b)
[4] The purpose of part (b) is to double check your answer to part (a) and to make sure you
understand the language L. Write a program which counts the number of strings in L for
each length k for k ≤ 16. To check the strings of length k, you can use a loop like this:
for (i=0; i < (1 << k); i++)
{
1. Create a string w which corresponds to the
binary representation of the integer i.
2. Check if w is in L.
}
(c)
[3] Let L 2 = L 1 ∩ (01)* 11(10)* Describe L 2 using a set descriptor notation. Don’t forget
about v.
(d)
[10] Prove that L 2 is not regular using the pumping lemma.
(e)
[2] Given that that L 2 is not regular use this to prove that L 1 is not regular.
(f)
[4] For all strings w in the language L 1 such that the length of w is at least four, prove that
there exists some way to factor w as w = x y z such that |xy| is at most four, y is not the
empty string and xy * z is a subset of L 1 . Hint: Break it into two cases (one where the
length of u is one and the other case where the length of u is greater than one).
-22.
3.
Consider the following rightmost derivation:
S =>
W T T =>
W T a b =>
W U V W a b =>
W U V a a b =>
W U c c V a a a b =>
W U c c b b a a a b =>
W V V c c b b a a a b =>
W V b b c c b b a a a b =>
W b b b b c c b b a a a b =>
B b b b b c c b b a a a b =>
W W W b b b b c c b b a a a b =>
W W b b b b c c b b a a a b =>
W a a b b b b c c b b a a a b =>
aabbbbccbbaaab
(a)
[4] Draw the parse tree that corresponds to this derivation.
(b)
[3] Use your parse tree from (a) to find a leftmost derivation.
(c)
[3] What are u, v, x, y, z as per the pumping theorem?
Regular context-free grammars.
(a)
[7] Use a DFA for the language L = {w ∈ {a, b}* : the number of a’s is odd and
the number of b’s is not divisible by 3} to construct a regular context-free grammar
for L.
(b)
4.
5.
[3] Give a context-free grammar for L from part (a) which is not regular.
Design context-free grammars for the following languages:
(a)
[5] L 1 = {u u R v v R : u, v ∈ {0, 1}* , |u| ≥ 2, |v| ≥ 1}.
(b)
[5] L 2 = {1 p 0q 1r 03q 1s : p ≥ 2, q ≥ 0 , r ≥ 0 s ≥ 3}.
(c)
[5] L 3 = {a n b m : 2 n ≤ m ≤ 5 n}.
(d)
[5] L 4 = a p b q c r d s where (r + s) = 2 ( p + q), and p, q, r, s ≥ 0}.
[10] Consider the alphabet Σ = {a, b, (, ), ∪ , *, φ }. Construct a context-free grammar
that generates all regular expressions over {a, b}. Hint: start from our definition of a regular expression.
-36.
Let P be a finite set of ordered pairs of nonempty strings over some alphabet Σ. A match
of P is any nonempty string w such that for some n > 0 and some (not necessarily distinct)
pairs (u1 , v 1 ) (u2 , v 2 ) . . . (u n , v n ) in P , w = u1 u2 . . . u n = v 1 v 2 . . . v n .
Example: If P = {(a, ab), (b, ca), (ca, a), (abc, c)}, then abcaaabc is a match of P since if
the following five pairs are chosen, the concatenation of the first components and the concatenation of the second components are both equal to abcaaabc:
(a, ab)(b, ca)(ca, a)(a, ab)(abc, c).
(a)
[5] Prove that this system has a match:
P = {(aa, a), (aaa, a), (aab, a), (aab, ab), (c, aab), (c, ccc), (d, dd)}.
(b)
[5] Prove that the following system has no match:
P = {(a, cab), (abc, a), (abc, ab), (ab, ba), (c, bcca) }
(c)
[5] Suppose you are given an algorithm that decides whether or not a system P defined
over Σ1 = {0, 1} has a match. Describe how you could use this algorithm to determine
whether a system Q defined over Σ2 = {a1 , a2 , . . . , a k } has a match.
(d)
[5] Show how you apply your tactic from part (c) to the system
P = {(aa, a), (aab, a), (ac, cdd) }
defined over Σ = {a, b, c, d}.
(e)
[5] Define the length of a system P, denoted by |P|, where
P = {(u1 , v 1 ), (u2 , v 2 ), . . . , (u n , v n )}
to be
n
Σ ( | ui | + | vi | ).
i=1
Suppose the algorithm described in step (c) takes time O( f (|P|). Give an upper bound on
the time required to solve the arbitrary problem Q (based on your answer to part (c)).
Thought question: Design an algorithm to solve the problem described in 6(c) above.
Download