3
CS3133 HW#1 DUE: Tuesday, September 3 1. (9 points) For each of the following languages over { } 0,1 , produce a DFA to accept it. a) L 0 = z | z 3 { } . b) 1 L = the set of all strings with exactly one occurrence of 00. That is, 1011001101 1 L but 10110001101 1 L . c) 0 1 ~ L L . 2. (10 points) For any language L, define the language ( ) ( ) ( ) ( ) ( ) { } | NotPrefix L w w L x wx L x ε = = So if { } 0| 0 n L n = , then ( ) NotPrefix L = , and if { } , 0101, 01, 11 L ε = , then ( ) { } 0101,11 NotPrefix L = . Show that if L is regular, then NotPrefix(L) must be regular. 3. (8 points) For each of the following conjectures, state whether it is true or false and justify your answer. a) Conjecture: For any languages 0 L and 1 L , 0 1 L L = if and only if * * 0 1 L L = . b) Conjecture: For any Σ and any * L ∈Σ , if L is infinite then ~L is finite.

HW1-13 - Worcester Polytechnic Institute

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: HW1-13 - Worcester Polytechnic Institute

CS3133 HW#1

DUE: Tuesday, September 3 1. (9 points) For each of the following languages over { }0,1 , produce a DFA to accept it.

a) L0 = z | z ≤ 3{ } .

b) 1L = the set of all strings with exactly one occurrence of 00. That is, 1011001101 1L∈ but 10110001101 1L∉ . c) 0 1~L L∩ . 2. (10 points) For any language L, define the language

( ) ( ) ( )( ) ( ){ }|NotPrefix L w w L x wx L x ε= ∈ ∧ ∃ ∈ → =

So if { }0 | 0nL n= ≥ , then ( )NotPrefix L =∅ , and if { }, 0101, 01, 11L ε= , then

( ) { }0101,11NotPrefix L = . Show that if L is regular, then NotPrefix(L) must be regular. 3. (8 points) For each of the following conjectures, state whether it is true or false and justify your answer.

a) Conjecture: For any languages 0L and 1L , 0 1L L= if and only if * *0 1L L= .

b) Conjecture: For any Σ and any *L∈Σ , if L is infinite then ~L is finite.

Page 2: HW1-13 - Worcester Polytechnic Institute

CS3133 Solutions to HW#1

1. a) 0L is accepted by the DFA

M0 = q0 ,q1,q2 ,q3,qfail{ }, 0,1{ },δ ,q0 , q0 ,q1,q2 ,q3{ }( ) , where

being in state qi , 0 ≤ i ≤ 3, "means" that i input symbols have been read.

0 1 1

1 2 2

2 3 3

3

0 1

fail fail

fail fail fail

q q qq q qq q qq q qq q q

δ

b) 1z L∈ if and only if one instance of 00 has been read and then every 0 that follows is either the last character in z or is followed by a 1. In the following acceptor for 1L , states

0q and 1q "mean" that no instance of 00 has been read, and states 2q and 3q mean that exactly one instance of 00 has been read. If the last symbol read was 0 then the machine is in 1q or 3q , and if the last symbol read was 1 then the machine is in 0q or 2q . If more than one instance of 00 has been read, then the machine is in state failq .

{ } { } { }( )1 0 1 2 3 0 2 3, , , , , 0,1 , , , ,failM q q q q q q q qδ=

0 1 0

1 3 0

2 3 2

3 2

0 1

fail

fail fail fail

q q qq q qq q qq q qq q q

δ

c) 0 1~L L∩ is the set of all strings of length at most 3 which have either no occurrences of 00 or at least one occurrence of 000. So

{ }0 1~ ,0,1,01,10,11,000,010,011,101,110,111L L ε∩ = Since we don’t care about a minimal number of states, we can design the machine with state zq denoting that input string z has been read, and state failq denoting that the input which has been read is not a prefix of any string in our language. Language 0 1~L L∩ is

accepted by the DFA { } { } { } { }( )0 1| 3 , 0,1 , , , | ~z fail zq z q q q z L Lεδ≤ ∪ ∈ ∩ , where

0 1~L L∩ is as listed above, and with transition function ( ), if 3

,, otherwise

zaz

fail

q zq a

⎧ <⎪= ⎨⎪⎩

for

{ } { }*0,1 , 0,1z a∈ ∈ , and ( ) ( ),0 ,1fail fail failq q qδ δ= = .

Page 3: HW1-13 - Worcester Polytechnic Institute

2. If L is regular, then there is a DFA ( ), , , ,M Q s Fδ= Σ such that ( )L M L= . Construct*F as the set of all states q F∈ for which there is a path in M from q to a state of F.

Removing all states of *F from F yields a machine which accepts NotPrefix(L). Claim: { }( )* *, , , , |M Q s q F q Fδ= Σ ∈ ∉ accepts NotPrefix(L).

Proof: We need to show that for each of the following three cases and for any *z∈Σ , z∈NotPrefix L( )( )⇔ z∈L M *( )( ) .

Case 1 δs, z( )∉F

So ( )z NotPrefix L∉ . Since { }*|q F q F F∈ ∉ ⊆ , then δs, z( )∉ q∈F |q∉F *{ } .

So z ∉L M *( ) . Likewise, if z ∉L M *( ) , then either δs, z( )∉F or there is a nontrivial

path from δs, z( ) to a state of F. In either case, ( )z NotPrefix L∉ .

Case 2 δs, z( )∈F * .

By the definition of *F , there must be a nonempty x leading from δs, z( ) to a state

of F. That is δδs, z( ),x( )∈F

for some x ≠ ε . So δs, z( )∉NotPrefix L( ) . and z ∉L M *( ) .

Case 3 δs, z( )∈ { }*|q F q F∈ ∉ .

Clearly z∈L , and by the definition of M * , z∈L M *( ) . But since z is not a

proper prefix of any string belonging to L, it must follow that z ∈NotPrefix L( ) .

3. a The conjecture is false. If L0 = 0{ } and L1 = 0{ }*, then 0 1L L≠ but * *

0 1 1L L L= = .

b The conjecture is false. Choose { }0,1Σ = and L as the binary strings ending in 0, which contains the even natural numbers and hence is infinite. Language ~L contains the odd binary numbers and hence is infinite also. The reason for the word “contains” above is that these languages also contain binary numbers with leading 0’s. But, clearly, any set containing an infinite set must be infinite.