(10 points) Find an s-grammar for the language .
Solution
(10 points) Convert the following grammar into CNF and GNF.
(a).
Solution
First eliminate -productions. This gives
There is a unit-production, , so we must remove it from the grammar and get
CNF
We can now apply the construction and get
and
GNF
(b).
Solution
First eliminate -productions. This gives
This has introduced a unit-production, which is not acceptable in the construction of using Theorem .
CNF
We can now apply the construction and get
and
GNF
By introducing productions , we can convert the grammar into Greibach normal form.
(15 points) Use the CYK algorithm to determine whether the string is in the language generated by the grammar
Solution
For the string .
Let be a substring of and also let , and . Then, we compute for . If in , , otherwise .
Step 1.
, , , , .
Step 2.
, , , .
Step 3.
, ,
Step 4.
,
Step 5.
Since , the string is in the language.
(15 points) Construct npda's that accept the following languages on
Solution
Start with an initial in the stack. Put a mark a on the stack when input alphabet is an a, consume a mark a when input is a . When all 's in the stack are consumed, put a mark to the stack when input is a . After input becomes , eliminate a mark on the stack. The string will be accepted if the stack has only left when the input is completed.
(20 points) Show that the following languages on are not context free:
Solution
The language is context-free. A grammar for it is
Solution
Given , we pick which is in . It is easy to see that the only chance for the adversary to win is to choose for . Then the pumped string is However, for , we see immediately that
That means , so is not context-free.
(10 points) Construct Turing machines that will accept the following language on
Solution
A transition graph with is
(20 points) Design Turing machines to compute the following functions the largest integer less than or equal to for and positive integers represented by unary.
Solution
Start by removing the leftmost , then move to the rightmost and mark it by replacing it with . The read-write head then moves back to the leftmost and repeat the above process until there are no more 's. Finally, we replace all the marked 's by 's to complete the computation. The transition graph of a Turing machine with is given below.