hw5sol - CS 181 - Winter 2005 Formal Languages and Automata...

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

View Full Document Right Arrow Icon
CS 181 — Winter 2005 Formal Languages and Automata Theory Problem Set #5 Solutions Problem 5.1. (10 points) Recall the shuffle operator from Homework 2. Prove or disprove: 1. Context free languages are closed under shuffle. Solution We will show that context free languages are not closed under shuffle! Consider the languages L 1 = { 0 n 2 n | n 0 } and L 2 = { 1 m 3 m | m 0 } . Then the shuffle of the two languages (denoted SHUFFLE ( L 1 ,L 2 )) will contain the words that have an equal number of 0’s and 2’s, and equal number of 1’s and 3’s and morover, no 2 occurs before a 0 and no 3 occurs before a 1. Assume that ( L 1 2 ) is context-free. Then we know that context free languages are closed under intersection with regular languages. Consider intersecting ( L 1 2 ) with 0 * 1 * 2 * 3 * . Then we get precisely the language { 0 n 1 m 2 n 3 m | n,m 0 } . However, notice that this language is not context free. Intuitively, this is because we will need to recall n before m even though m is the last number we stored. This is not possible using a stack! To formally show this language is not context free, we can use the pumping lemma but we leave this as an exercise. 2. Let L be context free and R regular. Then the shuffle of L and R is context free. Solution We will show that in fact the shuffle of L and R is context-free. We do this by building a PDA for ( L,R ) given a PDA for L and a DFA for R . Let P = ( Q L , Σ , Γ L ,q L ,F L ) be a PDA accepting L and M = ( Q R , Σ R R R ) be a DFA accepting R . Our construction of the PDA for shuffle will use ideas from the construction showing the context free languages are closed under intersection with regular languages and from our construction showing regular languages were closed under shuffle. In particular, we define the PDA N = ( Q L × Q R , Σ , Γ ,δ, ( q L R ) L × F R ) . The transition function nondeterministically decides whether or not to feed the next input symbol to P or to M . In other words, (( q 0 ,p 0 ) ,b ) δ (( q,p ) ,w,a ) if and only if one of the following hold ( q 0 ) δ L ( q,w,a ) and p 0 = p . In this case, we update the PDA and let the DFA idle.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

hw5sol - CS 181 - Winter 2005 Formal Languages and Automata...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online