The following is a solution outline for the practice final. I did this quickly by your request so let me know before the weekend if there are any major gaffs! Please generate your own solutions before you look at these!
1. Consider the context-free grammar G=(V,T,P,S) where P is the set of productions:
S-->aB
B-->Sbb
S--> epsilon
2. Consider the PDA M=({q0,q1,q2},{a},{A,B},delta,q0,A,{q0}) with instructions delta(q0,a,A)={(q1,BA)}, delta(q1,a,B)={(q0,epsilon)} and delta({q1,epsilon,B)={(q2,B)}.
3. Fill in the following chart with Y if the set of languages in the row is closed under the
property in the column and N if it is not.
Give a brief justification for 2 of your answers in each row.
| union | intersection | concatenation | complement | |
| regular languages | Y | Y | Y | Y |
| context-free languages | Y | N | Y | N |
| recursive languages | Y | Y | Y | Y |
| r.e. languages | Y | Y | Y | N |
The proofs for regular languages are shown in the book in section 3.2.
The Y proofs for for context-free languages are shown in section 6.2.
The N proof for the intersection of context-free languages is based on the following: L1 = {aibicj} and L2 = {aibjcj} are both CFLs but their intersection L3 = {aibici} is not a CFL by the pumping lemma for CFLs.
The N proof for the complement of a context-free language is based on the following: If context-free languages were closed under both union and complement then they would be closed under intersection. They are not closed under intersection and they are closed under union, so they must not be closed under complement.
The proofs for recursive languages are shown in the book in section 8.2. Intersection can be shown by constructing a machine which interleaves the computations of two machines. Concatenation can be shown by nondeterministically guessing the boundary between the end of the first substring of the concatenated string and the beginning of the second substring of the concatenated string. The "concatenation machine" executes the first machine on the first part and and the second machine on the second part. To be a concatenated string, both substring executions must terminate with a Y. Note that if an input string is a concatenation, some nondeterministic guess at the boundary will provide an accepting computation.
For r.e. languages, U and complement are covered in section 8.2. For concatenation, construct a 2 tape TM which nondeterministically guesses the boundary between the first and second substrings. Put the first string on the first tape and the second string on the second tape and interleave the execution of both machines. For intersection, you can also use a 2 tape turing machine. Copy the string on the second tape and interleave computations on the first and second tape. If the machine simulated by the first tape and the machine simulated by the second tape both accept, then make your constructed "intersection TM" accept the string.
4. Consider the language L={0n1n2n| n > 0}.
5. Let M=({q0},{1},{1,B},delta,q0,B,F) be a Turing machine with instructions delta(q0,1)=(q0,1,R) and delta(q0,B)=(q0,B,R).
6. What kind of machines accept r.e. languages?
7. Consider the following classes: recursively enumerable (r.e.) languages, languages accepted by deterministic FSAs, context-free languages (CFLs), recursive languages, all languages, regular langugages, deterministic context-free languages (DCFLs), languages accepted by DTMs.
Draw a diagram which shows the subset relationships
between these languages.
The set of all languages properly contains the set of r.e. languages
The set of r.e. languages properly contains the set of recursive languages
The set of recursive languages = the set of languages accepted by DTMs
The set of recursive languages properly contain the set of CFLs
The set of CFLs properly contain the set of DCFLs
The set of DCFLs properly contain the set of regular languages
The set of regular languages = the set of languages accepted by deterministic FSAs
For the given language classes, show by exhibiting particular languages, which subset relationships in the diagram are proper. For example, if you have claimed that language class A is a proper subset of language class B, then give an example of a language that is in class B but not in class A.
8. Show that it is undecidable to determine the following question:
"Given TMs M1 and M2, is L(M1)=L(M2)?".
Assume towards a contradiction that the language L=={e(M1)e(M2)| M1 and M2 are TMs and L(M1)=L(M2)} is recursive, i.e. there exists an always halting turing machine M= which accepts L=.
We'll construct an always halting TM which accepts Lemptystring={e(M)| M a TM and M accepts the empty string}. Since Lemptystring is not recursive, this will be a contradiction.
Given a TM M, we will construct a TM M' which does the following on input x:
Let M0 be a TM which doesn't accept anything, i.e. L(M0)=emptyset.
Now we'll construct TM M'' which accepts Lemptystring. M''
takes as input e(M) and
Hence M'' is an always halting Turing machine which accepts Lemptystring. Contradiction.