Download presentation
Presentation is loading. Please wait.
Published byCollin McLaughlin Modified over 8 years ago
1
1 Key to Homework #3 (Models of Computation, Spring, 2001) Finite state control with a 4-way read/write head 8 8 8 8 8 8 8 8 8 8 Figure (a)Figure (b) (over) Answer: (See next slide.) 1. (a) We know how to formally define a Turing machine with one-dimensional (1-D) tape and a finite state control with one two-way read/write head. How will you extend this definition and define a 2-D Turing machine with one two dimensional tape and a finite state control with one read/write head that can move up, down, to the left, to the right, or stay? (See Figure (a) below.) Write a complete formal definition of such computational model with a tuple (i.e., set of information) as we did for the Turing machines. 2. (b) Design a 2-D Turing machine which draws a figure of eight with 8’s on the blank tape as show in Figure (b) below. The machine should be in an accepting state when it has completed the drawing. What is the minimum number of states needed for this machine? Why? Your answer for this question will be evaluated according to the soundness of your argument.
2
2 1. (a) Answer: The 2-D TM can be formally defined as 6-tuple M = ( Q, , , , q 0, F ), where Q is the finite set of states, is the set of tape symbols (alphabet) including the blank symbol, usually denoted by B (a square box in the text), is the set of input symbols, which is a subset of , q 0 is the start state, F is the set of accepting states (F Q ), and is the transition function which maps Q Q {L, N, R, U, D}, where L, N, R are as defined in 1-D TM, and U and D are for moving up and down from the current position. 1.(b) Answer: Figure (a) below shows a straightforward design with 14 states, each state drawn at the relative location where the machine writes 8. Figure (b) is an improved version with 10 states. Notice that to reduce the number of states this machine uses the symbol written on the tape in the past moves. (For minimality, see next slide.) (B,8,R)(B,8,D) start (B,8,D) (B,8,L)(B,8,U) (B,8,R) (B,8,L) (8,8,U) (B,8,U) (8, 8, N) Figure (a) 2-D TM with 14 states (B,8,R) start (8,8,R)(B,8,L) (B,8,D) (8, 8’,D) (B,B,R) (B,B,L) (B, 8 *, R) (8, 8, D), Figure (b) 2-D TM with 10 states (B, 8 *,L) (8’, 8, L) (B,8,U) (8 *, 8, L) (B, 8, D) (8 *, 8, N)
3
3 Figure (a) 2-D TM with 8 states (B,8’,R)(B,8,R) start (B,8,D) (B,8,L) (8,8,N) (B,8,U) (8,8,D)(8’,8,R), (8,8,R), ** Notice that with the above idea, by increasing the number of different symbols to some constant k that can be written at the start state, it is possible with the same automaton shown above to draw a sequence of k square block of 8’s as illustrated below. 8 8 8 8 8 block 1 8 8 8 8 8 2 8 8 8 8 8 3 8 8 8.. k 8 8 8 Surprisingly, after Sam put the key answers on the web, TA Yining reported that one of our students made 8- states automaton! I thought what should his idea be, and got the following. This implies that my proof in previous slide is incorrect.
4
4 The question concerning the minimality of the number of states is challenging. The argument is based on the minimum number of states required to write a symbol on a blank cell located at the distance (going along vertical and/or horizontal direction) of k blank cells from the current position. For the formal argument we need the following definition. Definition: For a given position p on a 2-D tape, we say a blank cell c is in an open column (or row) with respect to p, if c is located in the same column (or row) of p, and in the extension of the column (or row) from p to c there are only blank cells. Figure (a) below shows an example of cell c which is in an open row with respect to position p, where we assume that no symbol is written to the right of cell c. Claim: For any 2-D TM which is located in a position p, it takes at least k states to write (in a finite number of steps) a symbol on a blank cell c that is in an open column (or row) with respect to p separated by k cells. Proof. Suppose that the machine takes less than k. Then as Figure (b) below illustrates, the machine should move to the right entering a previous state (say state i). Notice that in j+1 st cell, the machine will write a i, and move to the right, and on the next blank cell, write a i+1, and so non. These transitions form a cycle and the machine will keep moving to the right. Now, using the above claim, we can prove the minimality (10 states) of the 2-D TM shown in Figure (b) in the preceding slide. Notice that the machine writes top row first, and comes down along the center column (writing at the center). Then the machine writes the bottom row. This way we can minimize the number of cells to be written that are in an open column or row with respect to possible machine positions. Notice that once the four corners have been written, the machine can move to those corners along the vertical column until it hits a flag (see the star marked 8’s). This can be done by a self-looping transition as shown in the state transition graph (see the highlighted loop). pca b Figure (a) 1j<k2i... (B,a 1,R)(B,a 2,R)(B,a i,R) (B,a j,R) Figure (b)
5
5 2. For each of the following languages L i construct a DPDA (deterministic pushdown automaton) which accepts L i. For your answer it it enough to show the state transition graph of the automaton. (Make sure if your machine does not have a bug by running it with several short input strings.) (a) L 1 = {a i b j ; | i > j > 0 } (b) L 2 = {a i b j ; | i j > 0 } (c) L 3 = {a i b j ; | i j 0 } (d) L 4 = {a i b j | i > j > 0 } (e) L 5 = {a i b j | i j > 0 } (f) L 6 = {a i b j | i j 0 } (g) L 7 = { a i b k c i | i, k > 0 } (h) L 8 = { a i b k c i | i, k 0 } start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/ ) (;, a/ ) (a) L 1 = {a i b j ; | i > j > 0 } start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/ ) (;, a/ ), (;, Z 0 /Z 0 ) (b) L 2 = {a i b j ; | i j > 0 } start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/ ) (;, a/ ), (;, Z 0 /Z 0 ) (c) L 3 = {a i b j ; | i j 0 } Answers: ( ;, Z 0 /Z 0 ) (;, a/a )
6
6 start (a, Z 0 /Z 0 ) ( a, a/aa ) (b, a/ ) (d) L 4 = {a i b j | i > j > 0 } (e) L 5 = {a i b j | i j > 0 } start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/ ) start (f) L 5 = {a i b j | i j 0 } (a, Z 0 /aZ 0 ), (a, a/aa) (b, a/ )
7
7 (g) L 7 = { a i b k c i | i, k > 0 } start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/a ) (c, a/ ) ( , Z 0 /Z 0 ) (c, a/ ) start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/a ) (c, a/ ) ( , Z 0 /Z 0 ) (c, a/ ) (h) L 8 = { a i b k c i | i, k 0 } (b, Z 0 /Z 0 )
8
8 3. For each of the following grammars, construct a DPDA which accepts the language generated by the grammar, where S is the only nonterminal, and others are all terminal symbols. For your answer it it enough to show the state transition graph of the automaton. (a) G 1 : S aSbb | abb (b) G 2 : S aSbb | (c ) G 3 : S aSbb | ccc (a) L(G 1 ) = { a i b 2i | i > 0 } start (a, Z 0 /aaZ 0 ) (b, a/ ) ( , Z 0 /Z 0 ) (b, a/ ) (a, a/aaa) (b) L(G 2 ) = { a i b 2i | i 0 } start (a, Z 0 /aaZ 0 ) (b, a/ ) ( , Z 0 /Z 0 ) (b, a/ ) (a, a/aaa) (c) L(G 3 ) = { a i cccb 2i | i 0 } ( , Z 0 /Z 0 ) (b, a/ ) start (a, Z 0 /aaZ 0 ) (c, a/a ) (a, a/aaa) (c, a/a ), (c, Z 0 /Z 0 ) (c, a/a ), (c, Z 0 /Z 0 )
9
9 4. For each of the following languages, construct a DFA (deterministic finite automaton) which accepts the language. For your answer it it enough to show the state transition graph of the automaton. (a) L 9 = {x | x {a, m, t, o, u}* and x has automata as a substring. } (b) L 10 = {x | x {a, b, c} +, and the leftmost and the rightmost symbols in x are same.} start 1 2 m, t, o, u a a u m, t, o t o m a t a a, m, t, o, u m, o, u m, t, u t, o, u m, t, o, u m, o,m, t, o, u a a a a to state 1 Answer (a): to state 2 u
10
10 Answer (b): start a b c b, c a, c a, b a b, c a, c a, b c b a b c
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.