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

• Homework Help
• 5

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

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 SHUFFLE ( L 1 , L 2 ) is context-free. Then we know that context free languages are closed under intersection with regular languages. Consider intersecting SHUFFLE ( L 1 , L 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 SHUFFLE ( 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 , q R , F 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 , q R ) , F 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 , b ) δ L ( q, w, a ) and p 0 = p . In this case, we update the PDA and let the DFA idle.

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '08
• griebach
• Formal language, following grammar, context-free language, context free languages

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern