[PDF] Exercises

(b) the set of strings in {a} * whose length is divisible by either 2 or 7; (e) the set of strings in {O, 1, 2} * that are ternary (base 3) representa- (c) {x I x contains an even number of a's or an odd number of b's} A context-sensitive grammar (CSG ) or type 1 grammar is a type 0 (Sanity check: the string has five parse trees )



Previous PDF Next PDF





[PDF] Assignment 1, Due: Oct 17th

Problem 3 Write regular expressions for the following languages: (c) The set of strings of 0's and 1's whose number of 0's is divisible by five and whose 



[PDF] Homework 1 Problems

29 sept 2015 · (b) The set of all strings whose tenth symbol from the left end is a 1 3 (d) The set of strings such that the number of 0's is divisible by five, and 



[PDF] 60-354, Theory of Computation Fall 2011 - Asish Mukhopadhyay

Construct a DFA that accepts all strings over {0,1} decimal, is divisible by 5 (or, multiple of 5) 3 – The set of all strings such that each block of five consecutive symbols contains at least two 0's of all strings of 0's and 1's whose number of



[PDF] Homework 3 Solutions

Homework 3 Solutions 1 Give NFAs with the specified number of states recognizing each of (c) The language { w ∈ Σ∗ w contains at least two 0s, or exactly two 1s } with six Note that M′ accepts the string 100 ∈ C = { w w does not end with 00 }, so Thus, we first create a DFA state corresponding to the set {1, 2}:



Exercises

(b) the set of strings in {a} * whose length is divisible by either 2 or 7; (e) the set of strings in {O, 1, 2} * that are ternary (base 3) representa- (c) {x I x contains an even number of a's or an odd number of b's} A context-sensitive grammar (CSG ) or type 1 grammar is a type 0 (Sanity check: the string has five parse trees )



[PDF] DFA for all strings in which the number of 0s is even and the

number 0s read modulo 2, the other indicating the number of 1s read modulo 3 binary strings divisible by 3, the other accepting ternary strings divisible by 4 Solution: The language is identical to the set of strings w such that w mod 12 



[PDF] CS310 : Automata Theory 2019 - Cse iitb

Ashutosh Gupta and S Akshay Compile date: 2019-01-22 1 In the lecture, we added an (a) the set of binary strings whose number of 0's divisible by five



[PDF] Assignment 3 SOLUTIONS

Question 1 [3 marks] Use the product construction to construct a deterministic finite automaton (DFA) that accepts all binary strings with an even number of 0's  



[PDF] hmu_ch3pdf

Chapter 3 SNA Regular Expressions and Languages ** We begin this chapter by a single 0 followed by any number of l's or a single 1 followed by any number b) The set of strings of O's and l's whose number of O's is divisible by five



[PDF] regular languages and finite automata

Recognize strings representing numbers: Σ = {0,1,2,3 0, ,9 0, ,9 Note: 0, ,9 means 0,1,2,3,4,5,6,7,8,9: 10 transitions Proof idea: Complement the set of accept states ○ Example Is L = {w in {0,1}* : w is divisible by 3 OR w starts with 

[PDF] the shape of global higher education

[PDF] the shape of global higher education volume 4

[PDF] the shapiro test

[PDF] the shelly cashman series collection pdf

[PDF] the smith dc thanksgiving dinner

[PDF] the smith thanksgiving

[PDF] the social meaning of money pdf

[PDF] the social meaning of money summary

[PDF] the solution to the equation is x = .

[PDF] the solvable challenge of air pollution in india

[PDF] the space of love pdf

[PDF] the special theory of relativity pdf

[PDF] the specified image does not contain a windows node and cannot be used for deployment

[PDF] the standard 401k loan application

[PDF] the state of european car sharing

Exercises

Homework 1

Homework 1 301

1. Design deterministic finite automata for each of the following sets:

(a) the set of strings in {4,8,

1}* containing the substring 481;

(b) the set of strings in {a} * whose length is divisible by either 2 or 7; (c) the set of strings x E {O, 1}* such that #O(x) is even and #1(x) is a multiple of three; (d) the set of strings over the alphabet {a, b} containing at least three occurrences of three consecutive b's, overlapping permitted (e.g., the string bbbbb should be accepted); (e) the set of strings in {O, 1, 2} * that are ternary (base 3) representa tions, leading zeros permitted, of numbers that are not multiples of four. (Consider the null string a representation of zero.)

2. Consider the following two deterministic finite automata.

a b lr-r-r

2F I 2 1

a b 1 1IT3

2 3 1

3F 1 2

Use the product construction to produce deterministic automata ac cepting (a) the intersection and (b) the union of the two sets accepted by these automata.

3. Let M = (Q, E, h, s, F) be an arbitrary DFA. Prove by induction on

Iyl that for all strings x, y E E* and q E Q,

6(q,xy) = 6(6(q,x),y),

where 6 is the extended version of h defined on all strings described in

Lecture

3.

4. For k 1 and p 2, let

Ak,p {x E {O, 1, ... ,p -I} * I x is a p-ary representation of a multiple of k}. In Lecture 4 we gave a DFA for the set Aa,2, the multiples of three in binary, and proved it correct. Generalize the construction and proof to arbitrary k and p.

302 Exercises

Homework 2

1. The following nondeterministic automaton accepts the set of strings in

{ a, b} * ending in aaa. Convert this automaton to an equivalent deter ministic one using the subset construction.

Show clearly which subset

of {s, t, 'It, v} corresponds to each state of the deterministic automaton.

Omit inaccessible states.

a,b Q a a s t

2. The reverse of a string x, denoted rev x, is x written backwards.

Formally,

def reVE = E, def rev xa = a rev x. For example, rev abbaaab = baaabba. For A l:*, define rev A {rev x I x E A}. For example, rev {a,ab,aab,aaab} = {a,ba,baa,baaa}. Show that for any

A l:*, if A is regular, then so is rev A.

3. The Hamming distance between two bit strings x and y (notation:

H(x,'O)) is the number of places at which they differ. For example,

H(Ol1, 110)

= 2. (If Ixl ::f. 1'01, then their Hamming distance is infinite.) If x is a string and A is a set of strings, the Hamming distance between x and A is the distance from x to the closest string in A:

H(x,A) minH(x,'O).

ilEA

For any set A {0,1}* and k 0, define

Nk(A) {x I H(x, A) 5 k},

the set of strings of Hamming distance at most k from A. For ex ample, No({OOO}) = {OOO}, N1({000}) = {OOO,OOl,OlO,lOO}, and

N2({000})

= {O, 1P -{111}. Prove that if A {0,1}* is regular, then so is N2(A). (Hint: If A is accepted by a machine with states Q, build a machine for N2(A) with states Q x {O, 1, 2}. The second component tells how many errors you have seen so far. Use nondeterminism to guess the string yEA that the input string x is similar to and where the errors are.)

Homework 3

Homework 3 303

1. Give regular expressions for each of the following subsets of {a, b} *.

(a) {x I x contains an even number of a's} (b) {x I x contains an odd number of b's} (c) {x I x contains an even number of a's or an odd number of b's} (d) {x I x contains an even number of a's and an odd number of b's} Try to simplify the expressions as much as possible using the algebraic laws of Lecture

9. Recall that regular expressions over {a, b} may use

E, a, b, and operators +, *, and· only; the other pattern operators are not allowed.

2. Give deterministic finite automata accepting the sets of strings match-

ing the following regular expressions. (a) (000* + 111*)* (b) (01 + 10)(01 + 10)(01 + 10) (c) (0+ 1(01*0)*1)*

Try to simplify as much as possible.

3. For any set of strings

A, define the set

MiddleThirds

A = {y I 3x, z Ixl = Iyl = Izi and xyz E A}.

For example, MiddleThirds{ f, a, ab, bab, bbab, aabbab} = {f, a, bb}. Show that if A is regular, then so is MiddleThirds A. 304

Homework 4

1. Show that the following sets are not regular.

(a) {anb m

In = 2m}

(b) {x e {a, b, c}* I x is a palindrome; i.e., x = rev(x)} ( c) {x e {a, b, c} * I the length of x is a square} (d) The set PAREN of balanced strings of parentheses ( ). For ex- ample, the string " ( ) ( ) ) ( » is in PAREN, but the string ) ") is not.

2. The operation of shuffle is important in the theory of concurrent sys

tems. If x, y e we write x II y for the set of all strings that can be obtained by shuffling strings x and y together like a deck of cards; for example, ab II cd = {abed, acbd, acdb, cabd, cadb, cdab}. The set x II y can be defined formally by induction: f II {y}, xa II yb (x II yb) . {a} U (xa II y) . {b}. The shuffle of two languages A and B, denoted A II B, is the set of all strings obtained by shuffling a string from

A with a string from B:

U x lIy·

For example,

zEA !lEB {ab} II {cd, e} = {abe, aeb, eab, abed, acbd, acdb, cabd, cadb, edab}. (a) What is (01)* II (1O)*? (b) Show that if A and B are regular sets, then so is A II B. (Hint: Put a pebble on a machine for A and one on a machine for B. Guess nondeterministically which pebble to move. Accept if both pebbles occupy accept states.)

Homework 4 305

3. For each of the two automata

a b a b -+ 1 1 4 -+ IF 3 5

2 3 1 2F 8 7

3F 4 2 3 7 2

4F 3 5 4 6 2

5 4 6 5 1 8

6 6 3 6 2 3

7

2 4 7 1 4

8 3 1 8 5 1

(a) say which states are accessible and which are noti (b) list the equivalence classes of the collapsing relation defined in

Lecture

13: p q 'Vx E E* (6(P,x) E F {::::::> 6(q,x) E F)i (c) give the automaton obtained by collapsing equivalent states and removing inaccessible states.

306 Exercises

Homework 5

1. The following table defines four special types of CFGs obtained by

restricting productions to the form shown, where

A, B represent non

terminals, a a single terminal symbol, and x a string of terminals:

Grammar type Form oj produ.ctions

right-linear A-xB orA-x strongly right-linear A-aB orA-f left-linear A_ Bx orA-x strongly left-linear A-Baor A-f Prove that each of these four types of grammars generates exactly the regular sets. Conclude that every regular set is a CFL.

2. Prove that the CFG

8 -a8b I b8a I 88 I f

generates the set of all strings over {a, b} with equally many a's and b's. (Hint: Characterize elements of the set in terms of the graph of the function #b(y) -#a(y) as y ranges over prefixes of x, as we did in Lecture

20 with balanced parentheses.)

3. Give a CFG for the set PAREN2 of balanced strings of parentheses of

two types ( ) and []. For example, ( [() []] ( []» is in PAREN2, but [(] ) is not. Prove that your grammar is correct. Use the following inductive definition: PAREN2 is the smallest set of strings such that (i) f E PAREN2i (ti) if x E PAREN2, then so are (x) and [xl i and (iii) if x and y are both in PAREN2, then so is xy. (Hint: Your grammar should closely model the inductive definition of the set. For one direction of the proof of correctness, use induction on the length of the derivation. For the other direction, use induction on stages of the inductive definition of PAREN2. The basis is (i), and there will be two cases of the induction step corresponding to (ii) and (iii).)

4. Give a PDA for the set PAREN2 of Exercise 3 that accepts by empty

stack. Specify all transitions.

Homework 6

Homework 6 307

1. Prove that the following CFG G in Greibach normal form generates

exactly the set of nonnull strings over {a, b} with equally many a's and b's:

S-aB IbA,

A-aSlbAAla,

B -bS I aBB I b.

(Hint: Strengthen your induction hypothesis to describe the sets of strings generated by the nonterminals

A and B: for :z; :F E,

S +:z; #a(:z;) = #b(:z;),

A • 111

G

2. Construct a pushdown automaton that accepts the set of strings in

{ a, b} * with equally many a's and b's. Specify all transitions.

3. Let

b(n) denote the binary representation of n 1, leading zeros omitted. For example, b(5) = 101 and b(12) = 1100. Let $ be another symbol not in {a, I}. (a) Show that the set {b(n)$b(n+ 1) I n I} is not a CFL. (b) Suppose we reverse the first numeral; that is, consider the set {revb(n)$b(n+ 1) I n I}.quotesdbs_dbs20.pdfusesText_26