# hw8sol - CS 181 Winter 2008 Formal Languages and Automata...

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

CS 181 — Winter 2008 Formal Languages and Automata Theory Problem Set #8 Solutions Problem 8.1. (10 points) Show that P is closed under union, concatenation, and star. Solution Suppose A, B are two languages in P. Then let M A be the polynomial time Turing-decider for A and M B the same for B . The M A has some asymptotic runtime O ( n k ) and M B has runtime O ( n ) for some integers k and . Without loss of generality, we assume that k . We first show that A B P. We can build the following Turing decider M 1 for A B . M 1 first runs M A on its input, if M A accepts, then M 1 accepts. If M A rejects, then M 1 acts as M B on the same input. Clearly, this machine decides A B . Let us now analyze the running time of M 1 . Notice that for every input word, in the worst case we run M A then M B . Then this takes O ( n k + n ) = O ( n max( k,‘ ) ) = O ( n k ). Since k is a constant, it follows that M 1 runs in polynomial time. The existence of M 1 proves that A B P. Next, we show that AB P by building the Turing decider M 2 for it. Notice that given an input string of length n , there are n + 1 ways to partition it into two substrings (e.g. 123 can be partitioned as ε · 123 , 1 · 23 , 12 · 3 or 123 · ε ). M 2 simply tries each partitioning one at a time. For each partitioning, it runs M A on the left half of the string then M B on the right half. If both machines accept, then M 2 halts and accepts. If one of them rejects, then M 2 tries the next partitioning. If all partitionings fail, then M 2 rejects. Let us now analyze the running time of M 2 . Notice that for each partitioning, we run M A on a string of length at most n and M B on a string of length at most n . Thus, for each partioning M 2 takes time O ( n max( k,‘ ) ) = O ( n k ). However, there are n + 1 partitionings. Thus, in total, M 2 takes O ( n k +1 ) time. This is still polynomial and so AB P. Lastly, we show that A * P by building a Turing decider M 3 for it. M 3 will work by using dynamic programming. Notice that a string s is in A * if s A or if s can be written s = s 1 s 2 where s 1 , s 2 A * and s 1 , s 2 are non-empty (and so are proper substrings of s ). Then for input string s , we can first calculate which length 1 substrings are in A * (there are n of them). Then using this information, we can calculate which of the length 2 substrings are in A * (all n - 1 of them) by checking to see if they are in A , and otherwise checking to see if we can partition it into substrings in A * . We then continue this for the n - 2 length-3 substrings, the n - 3 length-4 substrings, etc. This continues until we can calculate whether the length n substring (namely, s itself) is in A * .

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 ]}

### 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