Академический Документы
Профессиональный Документы
Культура Документы
EXERCISES
(i) Is λ in ∑?
(ii) Is it true that λλλ=λ? Is it true for λi, i≥2?
(iii) Let x and y be two strings over ∑. Is the concatenation of x and y always
equal to the concatenation of y and x? Describe when this situation holds.
1.2 A string is infinite when its length is infinite. Let ∑ be an alphabet. Does ∑*
contain any infinite string? If we change the restriction that makes ∑ finite, and let
it be infinite, does it change the answer?
1.3 Let x, y and z be three strings over alphabet ∑. Prove that xy concatenated with z is
always the same as concatenating x with yz; this is, that concatenation is
associative.
1.4 For a string x, xR is the same string read backward. Prove that (xy)R=yRxR, for any
x y over ∑. (hint: try to define xR inductively)
1.5 Prove:
1.6 Let u, v, w, z be strings over ∑* such that uv=wz. Prove that there exists y in ∑*
such that:
either uy=w and v=yz,
or u=wy and yv=z
1.7 Let Li in ∑*, i=1,2,3, be three languages. Are the following claims true?
(i) (L1L2)L3=L1(L2L3)
(ii) (L1∪L2)L3=L1L3∪L2L3
(iii) L1(L2∪L3)=L1L2∪L1L3
(iv) (L1∩L2)L3=L1L3∩L2L3
(v) L1(L2∩L3)=L1L2∩L1L3
(vi) (LC)C=L
(vii) (LC)*=(L*)C
(viii) (L1∪L2)*=(L1*L2*)*
(ix) (L1L2∪L1)*=L1(L2L1∪L1)*
2
(x) (L1L2∪L1)*=L1(L2L1∪L2)*
(xi) (L1*)*=L1*
(xii) (L1L2)*L1=L1(L2L1)*
(xiii) L1=L1*
(xiv) (L1∩L2)*=L1*∩L2*
(xv) (L1+)*=(L1*)+
(xvi) (L1+)*=L1*
(xvii) L1+L1+=L1+
(xviii) (Ø)+=(Ø)*
In case the claims are false in the general case, try to describe in which particular
situations they are true.
1.8 Give examples of strings that belong and those that do not belong to the following
languages defined over {a,b}:
(i) {w | ∃ u (w=uuRu)}
(ii) {w | ww=www}
(iii) {w | ∃ u,v (uvw=wvu)}
(iv) {w | ∃ u (uu=www)}
1.9 Give formal expressions for the following languages over {0,1}:
1.10 Let ∑={a,b,c} and L={cixcj: i,j≥ 0, x=λ or x=aw or x=wb, w ∈ ∑*}. Is L=∑*? Is
L2=∑*?
3
Finite Automata
2.1 We are living in a building with 6 floors, and a new elevator is being installed.
Since your mum is telling everyone that you are studying computer science, the board
asks you to design the system that controls the decisions of the elevator.
4
2.4 Let M be the following NFA:
5
(xi) {w ∈ {a,b}* : |w|=3n, n ∈ N and w does not contain aba}
6
Regular Languages
c*(λ+a(a+b+c)*+(a+b+c)*b)c*
(i) Is L(E)={a,b,c}*?
(ii) Is L(EE)={a,b,c}*?
3.2 Build regular expressions that are equivalent to the following languages over
{a,b,c} of the strings that fulfill the following conditions:
3.3 A regular expression is ambiguous when there is a string that can be obtained
following two different ways. Which regular expressions are ambiguous?
(i) a((ab)*cd)*+a(ababcb*)*a*
(ii) aab*(ab)*+ab*+a*bba*
(iii) aaba*+aaaba+aabba*+a
3.4 Build DFAs that recognize the languages defined by the regular expressions:
(i) a*ba*ab*
(ii) b((aab*+a4)b)*a
(iii) ab[((ba)*+bbb)*+a]*b
3.5 Say whether the following equalities are true or false, where r, s and t are regular
expressions. (r=s means, L(r)=L(s))
(i) r(sr)*=(rs)*r
(ii) (r*s)*r*=(r+s)*
(iii) (rs+r)*r=r(sr+r)*
(iv) s(rs+s)*r=rr*s(rr*s)*
(v) (r+s)*=r*+s*
(vi) (λ+(0+1)*100)0*=λ+0+(0+1)*00
(vii) (λ+1)0*(1+110*)*=1*(0+11+111)*1*
(viii) (1+011+0011)*0(0+1+01)0(0+1)*=(0+1)*0(0+1)0(0+1)*
7
3.7 Find regular expressions for the DFAs defined in exercises 2.3 and 2.6.
(00+(1+01)(11+0)*10)*
3.10 Is it true that if a language is the union of non-regular languages, it can not be
regular? What about intersection? And concatenation? If it is true, prove it. Otherwise,
give counterexamples.
8
(ix) {0m1n: m ≠ n}
(x) {0m1n: (m,n)=1} (m,n) is the gcd
3.12 Let L, defined over {0,1}, the set of the strings that interpreted as a number in
binary are multiple of 3. Prove that L=LR.
9
Grammars
(i) The set of lists with compensated parenthesis, this is, where each left
parenthesis has its right parenthesis, and they are correctly nested.
(ii) The set of all strings over alphabet {a,b,.,*,(,),λ,↑} which are regular
expressions over {a,b}. We should distinguish between λ as the empty
string and λ as a symbol in the regular expression, which we denote as ↑.
(iii) {w ∈ (a+b)*:w=wR}
(iv) {wwR:w ∈ (0+1)*}
(v) The set {w#wR#:w ∈ (0+1)+}*
(vi) The language of such strings over {a,b} such that each prefix has at least
the same number of a’s as b’s.
(vii) {aibicjdj:i,j≥1}
(viii) {aibjbiaj:i,j≥0}
(ix) {0m1n:m>n≥0}
(x) {aibjck:i≠j or j≠k}
(xi) {0k1m0n:n=k+m}
(xii) {anbm:1≤n≤2m}
(xiii) {0i1j2k:i=j or j=k}
(xiv) {0n1m:m=n or m=2n}
(xv) {0n1m:m≤n≤2m}
(xvi) The set of all strings over {0,1} with the same number of 0 as 1.
(xvii) The set of all strings over {a,b} that have double numbers of a’s as b’s.
(xviii) a*c*b*+(a*d)*cb*
(xix) a*ba*ab*
(xx) a((ab)*cb*)*+a(ababcb*)*a*
(xxi) (a+b+c)*-{akbkck:k>0}
4.2 Prove that the previous grammars actually generate those languages
4.3 Let G be a CFG with m variables, whose productions do not have a right side with
length larger than k. Prove that if A
→
*
λ, there is a derivation of (km-1)/(k-1) steps
at most from A to λ.
Is possible to improve this lower bound?
4.4 Prove that for each grammar G there is a constant c such that if w ∈ L(G) and w≠λ,
then w has a derivation with at most c|w| steps.
4.5 A grammar is right linear if all its productions have the following shape, either
X→ wY or X→v, where w and v belong to ∑* and X and Y are variables.
Prove that for all right linear grammars there is another equivalent one which has all
the productions such as X→aY or X→λ, where a belongs to ∑.
4.6 Simplify and transform all grammars from ex. 4.1 to Chomsky Form.
10
4.7 Let L1 and L2 two CFLs. Prove that:
n
U (L )1 ( L2 ) n
n≥1
is a CFL.
(i) It generates the language of all strings with the same number of a’s
as b’s.
(ii) It is not ambiguous.
11
Pushdown Automata (PDA)
(i) {a2icbi:i≥0}
(ii) {a2i+1bi:i≥0}
(iii) {xcxR:x ∈ (a+b)*}
(iv) {x:x ∈ (a+b)* and |x|a=|x|b}
(v) The languages 1, 6, 7, 9, 11, 12 and 17 proposed in previous chapter.
5.2 Justify via pushdown automata that the following languages are not CFL:
(i) {aibjck:i<j<k}
(ii) {w ∈ (a+b+c)*:|w|a=|w|b=|w|c}
(iii) {anbncm:n≤m≤2n}
(iv) {aibjck:i≠j≠k≠i}
(v) {aibjck:i≠j≠k}
(vi) {aibjcidj:i,j>0}
(vii) {ww:w ∈ (a+b)*}
(viii) {aibjak:k=max(i,k)}
5.3 Prove via the pumping lemma that languages from exercise 5.2 are not CFL.
12
Turing Machines
6.1 Design a Turing Machine that accepts the following languages over ∑={a,b}
6.2 Build a TM which computes the parity function of the natural numbers:
f(n)= 0 if n is even
1 if n is odd
6.3 Design a copy machine C. C transforms bwb to b3wb (b is the blank symbol)
6.5 Build a TM that computes f(n,m)=n-m, for n,m Naturals. How do you cope with
n-m<0?
13
Decidability
7.2 Let f be a decidable function. Let N(f)={x|f(x)=0}. Prove that N(f) is e.r but it can’t
be recursive.
7.4 Consider the problem of testing whether a Turing machine M on input w ever
attempts to move its head left when its head is on the left-most tape cell. Formulate
this problem as a language and show that it is undecidable.
(b) Design a Turing machine that shifts the entire input string one
cell to the right. In this part, you are to give the formal
description of the machine (you can draw the state diagram, or
provide the delta function for the entire domain). Precisely,
you will design a Turing machine M such that, given an input
string w ∈ {0,1}*, M’s accepting configuration will be
qaccept#w.
14
15
Unsorted Exercises
prove that it accepts the language of all the strings over {0,1}* which length is odd
and that do not ever have the same symbol in consecutive positions.
2. Prove that the language of the strings over {0,1}* that do not have the substring 010,
is the same as L(E), where E is 1*(0+11+111)*1*
Give a CFG that accepts the language L over {a,b,#} defined by:
16
5. Let L1 and L2 be the languages represented by the following automata. Give the
minimal DFA that represents L1 ∪ L2 .
8. Let L be a regular language. What can we say about the following language
L1={w | wwRwwR ∈ L} ?
11. What can you say about L={w ∈ {a,b}* | abw=wba}? Is it the empty set? Is it
regular?
12. Build the minimal DFA that recognizes the strings w over {a,b}, such that their
length is larger than 4 and all the prefixes of length equal to 4 have the same number
of a as b. (11 states)
13. Build the minimal DFA equivalent to the following regular expression:
((a+b)*+c)(ac)*b+a (8 states)
17
14. We say that x is a root of w if ∃ n≥0 such that w=xn. Then, we define the root of a
language L as root(L)={x| ∃ n≥0 xn ∈ L}.
18