hwsoln06

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

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

Prof. Marvin Nakayama Homework 6 Solutions 1. Give pushdown automata that recognize the following languages. (a) A = { w ∈ { 0 , 1 } | w contains at least three 1 s } Answer: q 1 q 2 q 3 q 4 0 , ε ε 1 , ε ε 0 , ε ε 1 , ε ε 0 , ε ε 1 , ε ε 0 , ε ε 1 , ε ε Note that A is a regular language, so the language has a DFA. We can easily convert the DFA into a PDA by using the same states and transitions and never push nor pop anything from the stack. (b) B = { w ∈ { 0 , 1 } | w = w R and the length of w is odd } Answer: q 1 q 2 q 3 q 4 ε, ε \$ 0 , ε 0 1 , ε 1 0 , ε ε 1 , ε ε 0 , 0 ε 1 , 1 ε ε, \$ ε Since the length of any string w B is odd, w must have a symbol exactly in the middle position; i.e., | w | = 2 n + 1 for some n 0 , and the ( n + 1) th symbol in w is the middle one. If a string w of length 2 n + 1 satis±es w = w R , the ±rst n symbols must match (in reverse order) the last n symbols, and the middle symbol doesn’t have to match anything. Thus, in the above PDA, the transition from q 2 to itself reads the ±rst n symbols and pushes these on the stack. The transition from q 2 to q 3 nondeterministically identi±es the middle symbol of w , which doesn’t need to match any symbol, so the stack is unaltered. The transition from q 3 to itself then reads the last n symbols of w , popping the stack at each step to make sure the symbols after the middle match (in reverse order) the symbols before the middle. 1

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.

{[ snackBarMessage ]}

### Page1 / 6

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

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

View Full Document
Ask a homework question - tutors are online