Вы находитесь на странице: 1из 18

AUBER

(Models of Computation, Languages and Automata)

EXERCISES

Xavier Vera, 2002


Languages and alphabets

1.1 Let ∑ be an alphabet, and λ the empty string over ∑.

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

(i) There is no string x over {a,b}* such that ax=xb.


(ii) If x is in {a,b}* and abx=xab, then there exists n such that x=(ab)n
(iii) If w is a prefix of y and x is a prefix of yz, then either w is a prefix of x or x
is a prefix of w.

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

(i) Strings that contain 000 but do not contain 001


(ii) Strings with at least one substring with length ≥3 which appears 3 or more
times.
(iii) Strings which none prefix represents, in binary, a multiple of 3.
(iv) Strings with even length which codify an odd number.
(v) Strings which has one prefix with more 0’s than 1’s.
(vi) Strings with one suffix which is palindrome and length ≥3
(vii) Strings with a suffix equal to a prefix.
(viii) Strings that if start with 00, do not concatenate 11.
(ix) Strings that do not contain 000 and 111 at the same time.
(x) Strings we can concatenate another string to in order to get a palindrome
string.
(xi) Strings with a substring that codify a prime number larger than 5.
(xii) Strings which contain a number of 1’s multiple of 3.

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.

2.2 Let M be the following DFA

(i) Write down four strings accepted by M and the sequence of


configurations that prove it
(ii) Write down four strings that are not accepted by M.

2.3 Which are the languages accepted by the following automata?

4
2.4 Let M be the following NFA:

(i) Write down four strings accepted by M and the sequence of


configurations that prove it
(ii) Write down four strings that are not accepted by M.

2.5 Prove that the following automata

accepts the language L={aibj, aicj: i,j≥1}.

2.6 Give DFA’s that accept the following languages:

(i) Strings over {a,b} that end in aa.


(ii) Strings over {a,b} with three consecutive a’s.
(iii) Strings over {a,b} that do not contain the string aaa.
(iv) The set of all the strings over {a,b} such that each string of length 5
contains at least two a’s.
(v) The set of all the strings over {a,b} such that the fifth symbol from the
right is a b.
(vi) The strings over {a,b} that have a pair of a’s separated by a string of
length 4i, i≥0.
(vii) The set of all the strings over {a,b} where all pairs of a’s are just before a
pair of b’s.
(viii) Strings λ, 001 and 000101.
(ix) Strings over {0,1} that starts with 1 and that interpreted as binary numbers
are ≡0 mod 5.
(x) {w ∈ {a,b}* : |w|a=2n, |w|b=2m, m, n ∈ N}

5
(xi) {w ∈ {a,b}* : |w|=3n, n ∈ N and w does not contain aba}

2.7 Describe algorithms that decide:

(i) whether two automata M and M´ accept the same language


(ii) if an automata accepts, at least, one string
(iii) if an automata accepts the language which contains all strings with
odd length
(iv) whether an automata accepts a cofinite language.

6
Regular Languages

3.1 Let E be the following regular expression:

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:

(i) there is an even number of a’s in w,


(ii) there are 4i+1 b’s in w, i≥0
(iii) |w|=3i, i≥0
(iv) string abc does not appear in w.

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

3.6 Build regular expressions equivalent to the following DFA’s:

7
3.7 Find regular expressions for the DFAs defined in exercises 2.3 and 2.6.

3.8 Build a DFA equivalent to the regular expression:

(00+(1+01)(11+0)*10)*

3.9 Obtain the regular expression for the following automata

and simplify it until you get (11+10+0)*100*

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.

3.11 Prove that the following languages are not regular:

(i) {0m1n0m+n: m,n≥1}


(ii) {ww: w ∈ (0+1)+}
(iii) {(01)n(10)n: n≥0}
(iv) The set of all the strings over {0,1} with the same number of 1’s and
0’s.
(v) {w ∈ (0+1)*: w=wR}
(vi) {xxRw: x,w ∈ (0+1)+}
(vii) {0n: n is prime}
(viii) {0n: n is compound}

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.

3.13 Prove that if L is regular, LR is regular.

9
Grammars

Consider the following languages:

(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.1 Give CFGs that generate the previous languages

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.

4.8 Prove that the following grammar:

S→ aBS aBS | bAS | λ


A→ bAA | a
B → aBB | b

(i) It generates the language of all strings with the same number of a’s
as b’s.
(ii) It is not ambiguous.

4.9 Prove that for all languages L, L is CFL iff LR is CFL.

11
Pushdown Automata (PDA)

5.1 Give deterministic pushdown automata for the following languages:

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

(i) {abanb | n≥0}


(ii) {w | |w| is even}
(iii) {anbm | n≥1 and m≠n}
(iv) {w | |w|a=|w|b}
(v) {anbman+m | n≥0, m≥1}
(vi) {anbnanbm | n≥0, m≥0}
(vii) {anb2n | n≥1}
(viii) {ww | w ∈ {a,b}*}
(ix) {w | w=wR}
(x) Set of strings over {(,)} that have balanced parenthesis

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.4 Build a TM that computes f(n,m)=nm

6.5 Build a TM that computes f(n,m)=n-m, for n,m Naturals. How do you cope with
n-m<0?

6.6 Build a TM such that:

(i) Computes the integer function f(n)= floor(n/2)


(ii) Given a string w and an integer n≤|w|, moves the reader/writer to the n-
th symbol of w
(iii) Adds two binary numbers
(iv) Generate the complementary of a binary number
(v) Shifts a binary number to the left, inserting 0.

13
Decidability

7.1 Classify the following problems as recursive, e.r or non of them.

(i) A={x | ∃ x,y fx(y)=z}


(ii) A={x | ∃ y fx(y)=y}
(iii) A={x | fx(x)=x}
(iv) A={x | Dom(fx) is recursive}
(v) A={x | Dom(fx) is not recursive}
(vi) A={x | Im(fx) is recursive}
(vii) A={x | Im(fx) is not recursive}
(viii) A={x | Dom(fx) is e.r}
(ix) A={x | Dom(fx) is recursive}

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.3 Classify the following languages/problems as recursive, e.r or non of them.

(i) A={<x,y,z,t> | Mx(y)=z in t or less steps}


(ii) A={<x,y,z,t> | Mx(y)=z in more than t steps}
(iii) A={x | ∀ z Mx with input z halts in |z| steps}
(iv) A={<x,y,z,t> | Mx(t)=My(t)=Mz(t)}
(v) A={x | fx=Id}
(vi) A={x | fx(2000)↓ and fx(1000)↑}
(vii) A={x | ∃ y≠x fx=fy}
(viii) A={<x,y> | fx(y) ↑ or ( ∃ z≠x fx(y)=fz(y))}

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.

7.5 A common operation in Turing-machine programs involves “shifting over.” We


need to move the contents of each of the cells to the right of the current head position
one cell right, and then find our way back to the current head position.

(a) Give the high level description of how to perform this


operation.
Hint: Leave a special symbol to mark the position to which the
head must return.

(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

1. Given the following automata, which is minimal,

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*

3. Prove that L={w ∈ {0,1}* | ∃ u www=uu} is not regular.

4. Let R be the language over {a,b} accepted by the following automata.

Give a CFG that accepts the language L over {a,b,#} defined by:

L={x#y | x,y ∈ {a,b}* ∧ |x|=|y| ∧ x ∈ R}

16
5. Let L1 and L2 be the languages represented by the following automata. Give the
minimal DFA that represents L1 ∪ L2 .

6. Determinize the following automata.

7. Which is the DFA that represents the following language: L=LCa ?

8. Let L be a regular language. What can we say about the following language
L1={w | wwRwwR ∈ L} ?

9. Which of the following languages are regular?


• {anbm | n>m ∨ n<m}
• {anbm | n≥m ∨ n≤m}
• {anbm | n>m ∧ n<m}
• {anbm | n≥m ∧ n≤m}

10. How many states do we need to describe the following language,


Lij={ak| k is a multiple of i or j}?
HINT: Make some particular cases.

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

Prove that for any language L ⊆ ∑*:


λ ∈ L <=> ∑*=root(L)

18

Вам также может понравиться