Você está na página 1de 8

Final Exam in CDT314, Formal Languages, Automata and Theory of Computation

Date 2011-01-18 Teacher Stefan Bygde Examiner Gordana Dodig-Crnkovi c The exam is in three parts; Regular Languages, Context-Free Languages and Recursively Enumerable Languages. Each part corresponds to a midterm. If you passed the corresponding midterm, you dont need to write it. If you still decide to write it, the best of the exam score and the midterm score will count. This exam is open-book, and any material is allowed except for mobile phones and internet access.

Grading
Exam pass (grade 3) grade 4 grade 5 Regular Languages 7 9 12 Context-Free Languages 7 9 12 Recursively Enumerable Languages 6 8 10 The nal grade in the course will be an average of the above. But all parts have to be passed to get a grade.

How to write
Clearly state which problem on which part of the exam you solve Start every new problem on a new sheet of paper Good Luck! Stefan and Gordana

Regular Languages (14 points)


Problem 1 (8 points)

Consider the NFA above: 1. Convert the automation to a DFA using the subset construction. Show every step. 2. Using the resulting DFA (or the original NFA), create a regular expression by eliminating states. Clearly show every step of the algorithm.

Problem 2 (6 points)
For each of the following languages L. State weather L is regular or not, prove your answer! L is the language over = {a, b} such that any string w contains at least two as but at most two bs. L = {ww|w, w {0, 1}} where w is w but where zeroes are replaced with ones and vice versa. Example: if w = 0110, then w = 1001.

Context-Free Languages (14 points)


Problem 1 (8 points)
Consider the PDA below:

What language does it accept? (3 points) Make a context-free grammar accepting the same language. (5 points)

Problem 2 (6 points)
For the following languages, determine if they are context-free or not. Prove your answer. L = {w {a, b, c}|w every symbol in w occurs the same number of times} L = {ww|w, w {0, 1}} where w is w but where zeroes are replaced with ones and vice versa. Example: if w = 0110, then w = 1001. L = {xyx|x, y {a, b} }

Recursively Enumerable Languages (12 points)


Problem 1 (3 points)
What does the following Turing Machine do (in this gure is the blank)? It has input alphabet = {a, b} and tape alphabet = {a, b, , 1}. Explain what is on the tape after the machine has run. Also, do a test run with a string of length at least 3, containing both as and bs.

Problem 2 (3 points)
Show that the absolute value (positive dierence) |x y| is computable using primitive recursive functions (by dening a primitively recursive function for it). You may assume that LessThan, Subtract and if are primitively recursive functions. Show one example that |2 3| = 1.

Problem 3 (6 points)
For the following languages, determine if L is decidable or not. Prove your answer. Given a TM M and a string w. Does M accept w within 10 steps? Given a TM M , does M accept more than 10 strings? Given a TM M , does M accept any string of length 10?

Suggested Solutions
Regular Languages, Problem 1
1. The transition function is given below: ({0}, a) = {0} ({0}, b) = {1, 2} ({1, 2}, a) = {1, 2, 3} ({1, 2}, b) = {1, 2} ({1, 2, 3}, a) = {1, 2, 3} ({1, 2, 3}, b) = {1, 2} The resulting automation is shown below:

2. Starting from the previous DFA, we add lambda-transitions from the accepting states, to a single nal state.

Then we eliminate state q1 : 5

And nally state q2 :

The resulting regular expression is: a ( + bb a(a + bb a) ) Note that, depending on in which order you remove the states, you can get dierent regular expressions as result, although they should all describe the same language.

Regular Languages, Problem 2


Regular. At least two as is regular with the regular expression (a + b) a(a + b) a(a + b) and at most two bs is regular with the expression a (b + )a (b + )a , the intersection of these two regular languages is regular. Not regular. We apply the pumping lemma. Take for instance the string w = 0m 1m Clearly, w L and |w| m. Now let w = xyz such that |xy| m and |y| 1. Then y = 0k for some 1 k m. According to the pumping lemma xy 0 z = xz L, but xz = 0mk 1m , so xz L. Contradiction! Thus, L cannot be regular. /

Context-Free Languages, Problem 1


The language L over {a, b} containing twice as many as than bs. S SaSaSbS|SaSbSaS|SbSaSaS|

Context-Free Languages, Problem 2


Not context-free. The string am bm cm is in L, pumping of any block with length less or equal to m will lose symmetry with the other, and w will no longer contain the same number of symbols of each. Not context-free. Consider the string 0m 1m 0m 1m 0m 1m L for pumping. Context free. In fact L = {a, b} .

Recursively Enumerable Languages, Problem 1


The machine erases the input and put the count of as on the tape as a unary number. Testrun: q0 abab #q1 bab #bq1 ab #baq1 b #babq1 # #bab#q2 # #babq3 #1 #baq4 b#1 #bq4 ab#1 #q4 bab#1 q4 #bab#1 #q0 bab#1 ##q0 ab#1 ###q1 b#1 #bq1 #1 #b#q2 1 #b#1q2 # #b#q3 11 #bq3 #11 #q4 b#11 q4 #b#11 #q0 b#11 #q0 #11 #q5 11

Input was the string abab, and as expected, since abab contains two as, the tape contains 11 when the TM enter its nal state.

Recursively Enumerable Languages, Problem 2


abs(x, y) = if(less(y, x), Sub(x, y), sub(y, x)) Test run: Abs(2, 3) = if(less(3, 2), sub(2, 3), sub(3, 2)) = if(0, 0, 1) = p3 (0, 0, 1) = 1

Recursively Enumerable Languages, Problem 3


Decidable. Let the universal TM simulate w on M for ten steps. If M accepted return yes, if w was not accepted after ten steps, return no. Undecidable. If M accepts 10 strings it means |L(M )| = 10. This is a non-trivial language property and Rices theorem applies. Undecidable. This means that L(M ) contains a string w such that |w| = 10. Again, this is a non-trivial property of L(M ), so Rices theorem applies.

Você também pode gostar