• 沒有找到結果。

Common Mistakes

N/A
N/A
Protected

Academic year: 2022

Share "Common Mistakes"

Copied!
7
0
0

加載中.... (立即查看全文)

全文

(1)

• Please give details of your calculation. A direct answer without explanation is not counted.

• Your answers must be in English.

• Please carefully read problem statements.

• During the exam you are not allowed to borrow others’ class notes.

• Try to work on easier questions first.

• Please draw all the diagrams clearly.

Problem 1 (20 pts)

Consider the following two-tape TM:

q0

start q1 q2

q3

q4 qa

t → R t → R

0 → R t → 0, R

t → L t → L

0 → R 0 → L

t → L 0 → L 0 → R t → R

t → 0, R 0 → R

t → R t → R

Assume the initial configuration is t000000 in the 1st tape and t t . . . in the 2nd tape. Run the TM and give the sequence of configurations.

Answer

q0t 000000

q0t t t t t tt ⇒

tq1000000

tq1t t t t t t ⇒

t0q100000

t0q1t t t tt ⇒

t00q10000

t00q1t t t t ⇒

t000q1000 t000q1t tt

t0000q100 t0000q1t t ⇒

t00000q10 t00000q1t ⇒

t000000q1t t000000q1t ⇒

t00000q20t t00000q20t ⇒

t000000q3t t0000q300t ⇒

t00000q20t t000q2000t

t000000q3t t00q30000t ⇒

t00000q20t t0q200000t ⇒

t000000q3t tq3000000t ⇒

t00000q20t q2t 000000t ⇒

t000000q4t tq4000000t ⇒

(2)

t0000000q4t t0q400000t ⇒

t00000000q4t t00q40000t ⇒

t000000000q4t t000q4000t ⇒

t0000000000q4t t0000q400t ⇒

t00000000000q4t t00000q40t

t000000000000q4t t000000q4t ⇒

t000000000000 t qat t000000 t qat

Problem 2 (40 pts)

Construct a standard TM to recognize the following language:

{0n#1n#0n|n ≥ 0},

where Σ = {0, 1}. The # states ≤ 9 (including qaccept and qreject). You need to show the formal definition of the TM, but you can draw a state diagram instead of giving a formal definition of the transition function δ. You also need to explain the meaning of each edge.

Answer

T M = {Q, Σ, Γ, δ, q1, qa, qr}:

Q = {q1, q2, q3, q4, q5, q6, q7, qa, qr} Σ = {0, 1, #}

Γ = {0, 1, t, #, #1, #2, x, y, z}

δ is defined as the following state diagram:

(3)

q1 start

q2 q3

q4

q5

q6

q7 qa qr

x → R

0 → x, R

0 → R

# → R

y → R

1 → y, R

1 → R

# → R y → R

0 → y, L 0 → L

1 → L y → L

# → L

# → #1, R y → z, R

# → #2, R t → L z → L

#2 → L

#1 → R

z → L

All edges not specified go to the reject state.

That is, everytime we encounter a ‘0’ before ‘#’, we need to make sure there are a ‘1’ and a

‘0’ after the ‘#’. The first ‘0’ is then replaced by ‘x’, and the ‘1’ and ‘0’ after ‘#’ are replaced by ‘y’. If there is no more ‘0’ before #, we need to check if the replaced string is “x ∗ #y ∗ #y∗”.

Meaning of each edges:

• (q1, q2): replace a 0 before # by x.

• (q2, q2): before #, only 0 can be found.

• (q2, q3): find a #.

• (q3, q3): pass all checked symbols.

• (q3, q4): replace a 1 before the second # by y.

(4)

• (q4, q4): before the second #, only 1 can be found.

• (q4, q5): find a #.

• (q5, q5): pass all checked symbols.

• (q5, q6): replace a 0 by y.

• (q6, q6): go back until a x is found.

• (q6, q1): go to the next symbol. It can only be 0 or #.

• (q1, q7): In case the next symbol is #, change it to #1.

• (q7, q7): If # is found, change it to #2. And change all y to z.

• (q7, q1): Find the last #2.

• (q1, q1): Pass all z’s.

• (q1, qa): If #1 is found, it means there is exactly two # in the original input string.

Other Solutions

1.

q1 start

q2

q3 q4

q5 q6 q7

qa

qr 0 → t, R

0 → R x → R

# → R 1 → x, R

1 → R

# → R t → L x → L

0 → x, L 0 → L

x → L

# → L 1 → L

t → R # → R

x → R

# → R

x → R

t → R

All edges not specified go to the reject state.

(5)

q1

start

q2

q3

q4

q5 q6 q7

qa

qr

0 → t, R

¯0 → t, R

0 → ¯0, R

¯0 → R

# → R

x → y, R 1 → y, R

1 → R

# → R x → y, R

0 → x, L y → x, L

¯0, 1, # → L

t → R # → R

x → R

# → R

x → R

t → R

All edges not specified go to the reject state.

Common Mistakes

• # states > 9

• does not accept ##

• accepts ###

Problem 3 (40 pts)

Consider the following definition of nondeterministic TM:

N T M = (Q, Σ, Γ, δ, q1, qa, qr),

where qa 6= qr and δ : Q × Γk → P (Q × Γk× {L, R, S}k). Give a two-tape NTM to recognize the following language:

{aibjck|i, j, k ≥ 0 and i = j or i = k}.

The # of states ≤ 8 (including qaccept and qreject). You do not have give a formal definition. (A diagram is enough.) You also need to explain the meaning of each edge.

(6)

Answer

q1

start q2

q6

q3

q5 qa

q4

qr a/b/c/t → S

t → R

a → R t → a, R

b → S t → L

b → R t → S

c/t → S t → L

c/t → S t → L

c → R t → L

b → R a → L

c → R t → S

t → S t → S

t → S t → S

c → R t → S

b → R t → S

c → R a → L

t → S t → S

All edges not specified go to the reject state.

All a’s in the first tape are copied to the second tape. Then check if number of b’s or number of c’s is equal to number of a’s.

Meaning of each edge:

• (q1, q2): write a t at the beginning of the second tape.

• (q2, q2): copy a’s to the second tape.

• (q2, q3): in this path, number of b’s should be same as number of a’s.

• (q2, q4): in this path, both number of b’s and number of a’s are 0, but number of c is not.

• (q3, q3): check if number of b’s is equal to number of a’s.

• (q3, qa): accept if at the end of both tapes.

• (q3, q4): a c is found after b’s.

• (q4, q4): after a’s and b’s, there should only be c’s.

• (q4, qa): accept if at the end of the first tape.

(7)

• (q2, q5): in this path, number of c’s should be same as number of a’s, and a b is found after a’s.

• (q5, q5): only b∗ can be between a’s and c’s.

• (q5, q6): no more b’s.

• (q2, q6): in this path, number of c’s should be same as number of a’s, but no b is found after a’s.

• (q6, q6): number of c’s should be same as number of a’s.

• (q6, qa): accept if at the end of both tapes.

Another Solution

q1

start q2

q3

q4 q5

q6 qa

qr

a, b, c, t → S t → $, R

a → R t → R

b, c, t → S t → S

b → R t → S

c, t → S t → L

c → R t → L

t → R

$ → S b, c, t → S

t → L b → R t → L

c, t → S

$ → S

c → R

$ → S

t → R

$ → S

All edges not specified go to the reject state.

Common Mistakes

• does not accept , anbn, ancn, b+(i = k = 0), or c+(i = j = 0)

• accepts anbn

• assumes that there is a t at the beginning of tapes (or before the beginning of tapes)

參考文獻

相關文件

!  You have to modify a simple chat server to a multiplexing chat server. !  You don’t have to handle the

[r]

• To the right of the Draw mode buttons you find push buttons through which you can access all the functions that you need to define and solve the PDE problem: define

32.Start from the definition of derivative, then find the tangent line equation.. 46.Find the product of their slopes at there

(12%) A lamp is hung over the center of a circular table with radius 2m.. Find the height h of the lamp over the table such that the illumination I at the perimeter of the table

We can use should / ought to / have to / must + the base form of a verb to give advice and talk about necessity.. Should and ought to are less strong and less formal than have to

Let p be the probability that a healthy person gets the disease, r be the probability that an infected person recovers in each month.. Suppose there are 8

You receive the following letter from Alice Sharpton of the Harlequin Women’s Club who are planning a visit to Hong Kong later this year. Write a formal reply to