Midterm Examination for Discrete Mathematics

advertisement
姓名:___________________
Final Examination
Formal Language and Automata Theory
2015/01/14
學號:____________________
分數:________________
1. (20 pts) Fill in the following table about Chomsky hierarchy.
language type
language class name
type 3
recognition machine model
grammar model
Finite automata
type 2
type 1
context-sensitive language
type 0
unrestricted grammar
2. [20 pts] Design a context-sensitive grammar for the language { x {a,b,c}+ | #a(x) = #b(x) = #c(x) }. Note in a
context-sensitive grammar G = (N, , , S, P), every rule in P has the form    where both  and  are strings
of terminal and nonterminals with the restriction that  must contain at least one nonterminal and ||  ||.
Hint: First derive sentential form of the form (ABC)+ and then permute it so that A's are moved to the left and C's
moved to the right and finally rewrite A,B C to a,b,c, respectively. Namely, S * (ABC)+ * A*B*C* *
a*b*c*.
3. (20 pts) Let G be the context free grammar:
S  AB | BA
A a | XAX
B  b | XBX X  a | b
and M = (Q={q}, ={a,b}, ={S,A,B,X}, , S, q, F={}) be a PDA with one state q which is equivalent to G.
Assume M accepts by empty stack and L(M) = L(G). Determine the actions of M under all possible conditions by
filling in the following table? Note that there may exist zero, one or more than one actions under each condition.
Remember to mark '-' on each table cell which has no corresponding action.
topOfStack
(state, input)
(q,a)
(q,b)
(q,)
S
A
B
X
(q,)
4. [20pts] Let PDA M2 = ({p, q, t }, {a,b}, {A, B}, , p, B, {t}) where B is the bottom symbol, and  is given as
follows:
(p, a, B)  (p, AB)
(p, a, A)  (p, A)
(p, b, A)  (q, )
(q, , B) (t, )
Suppose M2 accepts by final state and empty stack, i.e., x is accepted iff (p, x, B) * (t,  ,  ).
(a) [6 pts]Derive a complete computation for the input aab from the initial configuration (p, aab, B):
(p, aab, B)  (p, ab, AB)  (_________________________________)
 _____________________________________________________
 ______________________________________________________
(b) Find 2 more inputs accepted by M2 besides aab.
_________________________________
(c) List 2 inputs not accepted by M2.
__________________________________
(d) [10pts] Find a context-free grammar G equivalent to M2.
5. (20 pts) Answer the following questions.
(a) What is the difference between a k-track Turing machine and a k-tape (k>1) Turing machine?
(b) What is a universal Turing machine (UTM)?
(c) What is a recursive language?
(d) What is the Turing-Church Thesis?
6. (20pts) Let M1= (Q1, , 1, s1, F1) be a DFA and M2 = (Q2, , , 2, s2,,F2) be a PDA which accepts by final state.
Similar to the case of finite automata, we can construct a PDA to accept the language L(M1) L(M2) using the product
construction. Complete the definition of the PDA M3 = M1xM2 which accepts the language L(M1) L(M2):
M3 = (Q1xQ2, , s3, , 3, F3) where s3 = (s1,s2) is the initial state,
(a) [5pts] F3 = ______________________ is the set of final states, and
(b) [10pts] How should 3 be defined suppose M2 makes no use of empty transition (of the form (_, ,_)  (_,_))?
(c)
And what should be the definition of 3 if M2 makes use of empty transitions?
7. [20pts] Design a standard Turing machine (TM) to accept the language { ambn {a,b}* | m > n}
which, on input x {a,b}* will first check that x is of the form a*b* and then check that #a(x) > #b(x). To simplify
problem, we assume the initial configuration is (s1, [x, 0) where x has been of the form a*b* so we need only check
that #a(x) > #b(x). The machine will ends in accept state t or reject state r depending on whether x is of the correct
form. The following is an informal description for the TM: Assume initially the tape is of the form [a*b*, then
(s1). R // move right to position 1;
(s2). while (input = '-' ) R ;
// '-' means the original 'a' has been processed
case(input) of {
'b', '' :
goto r
// reject since we find no 'a' to match following 'b' here!
'a' : '-' ; // replace 'a' by '-' so it will not be rechecked next time
(s3). while (input ='-' or 'a' ) R ; // keep moving right until 'b' or '' is found
case(input) of {
'' : goto t ; // accept since no b can match previous a.
'b' : '-' ; (s4). L ; // previous a matches this b, replace 'b' by '-' and move left
(s5).
move left until '[' ;
goto 1 // move left to position 0 and continue from 1
}
(t). halt
(r). halt
Note we have used (s1) ..(s5), (t) and (r) to mark the needed states in the TM.
7.1 translate the above description into (flow-chart-like) state-transition diagram
7.2 Write your formal result using the following table: Note : as indicated in the description, the machine has 5
states in addition to the accept(t) and reject(r) states.
[
a
state\\ symbol
s1
s2
s3
s4
s5
tF
halt
halt
rF (not used)
halt
halt
b

halt
halt
halt
halt
Download