# hwsoln03 - CS 341 Foundations of Computer Science II Prof...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 341: Foundations of Computer Science II Prof. Marvin Nakayama Homework 3 Solutions 1. Give NFAs with the specified number of states recognizing each of the following lan- guages. In all cases, the alphabet is Σ = { , 1 } . (a) The language { w ∈ Σ ∗ | w ends with 00 } with three states. 1 2 3 , 1 (b) The language { w ∈ Σ ∗ | w contains the substring 0101 , i.e., w = x 0101 y for some x,y ∈ Σ ∗ } with five states. 1 2 3 4 5 , 1 1 1 , 1 (c) The language { w ∈ Σ ∗ | w contains at least two s, or exactly two 1 s } with six states. 1 2 5 3 4 6 ε , 1 1 , 1 1 1 (d) The language { ε } with one state. 1 1 (e) The language ∗ 1 ∗ ∗ with three states. 1 2 3 ε 1 2. (a) Show by giving an example that, if M is an NFA that recognizes language C , swapping the accept and non-accept states in M doesn’t necessarily yield a new NFA that recognizes C . Answer: The NFA M below recognizes the language C = { w ∈ Σ ∗ | w ends with 00 } , where Σ = { , 1 } . 1 2 3 , 1 Swapping the accept and non-accept states of M gives the following NFA M ′ : 1 2 3 , 1 Note that M ′ accepts the string 100 negationslash∈ C = { w | w does not end with 00 } , so M ′ does not recognize the language C . (b) Is the class of languages recognized by NFAs closed under complement? Explain your answer. Answer: The class of languages recognized by NFAs is closed under complement, which we can prove as follows. Suppose that C is a language recognized by some NFA M , i.e., C = L ( M ) . Since every NFA has an equivalent DFA (Theorem 1.19), there is a DFA D such that L ( D ) = L ( M ) = C . By problem 3 on Homework 2, we then know there is another DFA D that recognizes the language L ( D ) . Since 2 every DFA is also an NFA, this then shows that there is an NFA, in particular D , that recognizes the language C = L ( D ) . Thus, the class of languages recognized by NFAs is closed under complement. 3. Use the construction given in Theorem 1.39 to convert the following NFA N into an equivalent DFA. 1 2 3 ε a a a,b b Answer: Let NFA N = ( Q, Σ ,δ, 1 ,F ) , where Q = { 1 , 2 , 3) , Σ = { a,b } , 1 is the start state, F = { 2 } , and the transition function δ as in the diagram of N ....
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

hwsoln03 - CS 341 Foundations of Computer Science II Prof...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online