hw7-answers - Solution to Homework 7 CS 321 1 Construct a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution to Homework 7 CS 321 1. Construct a Turing Machine (TM) that will accept the following languages. (a) [9.1.7(f)] L = a n b m a n + m : n ,m 1 Solution: To accept a n b m a n + m , the machine puts a special character at start and goes to last part of the string where there are as after bs. Then it starts to go delete a and go backwards deleting a or b from first part, and returning forwards. When it gets to the first char, it checks whether all the chars are processed. ( q ,a ) = ( q 1 ,x,R ) Replace first char ( q ,b ) = ( q 3 ,x,R ) ( q 1 ,a ) = ( q 1 ,a,R ) ( q 1 ,b ) = ( q 3 ,b,R ) Pass to bs ( q 3 ,b ) = ( q 3 ,b,R ) Go the the end ( q 3 ,z ) = ( q 3 ,z,R ) ( q 3 ,a ) = ( q 4 ,z,L ) Replace an a with z ( q 4 ,z ) = ( q 4 ,z,L ) ( q 4 ,b ) = ( q 3 ,z,R )Return until find a or b, replace them and go forward ( q 4 ,a ) = ( q 3 ,z,R ) ( q 4 ,x ) = ( q 5 ,z,R )If first symbol, go to final scan ( q 5 ,z ) = ( q 5 ,z,R ) ( q 5 , square ) = ( q f ,z,R ) (b) [9.1.8] L = { ww : w { a,b } + } . Solution: We will insert an x after the first character, and while we are shifting it forwards, we will keep testing if the string is of the form wxw. ( q ,a ) = ( q 1 ,y,R ) ( q ,b ) = ( q 1 ,z,R ) ( q 1 ,a ) = ( q a ,x,R ) Put x after first character ( q 1 ,b ) = ( q b ,x,R ) ( q a ,a ) = ( q a ,a,R ) Shift all the characters right ( q a ,b ) = ( q b ,a,R ) ( q b ,a ) = ( q a ,b,R ) ( q b ,b ) = ( q b ,b,R ) ( q a , square ) = ( q 2 ,a,L ) ( q b , square ) = ( q 2 ,b,L ) ( q 2 ,b ) = ( q 2 ,b,L ) Go to the start ( q 2 ,a ) = ( q 2 ,a,L ) ( q 2 ,y ) = ( q aa ,y,R ) Returned to the start, remember first char and go to the second part ( q 2 ,z ) = ( q bb ,z,R ) 1 ( q 3 ,a ) = ( q aa ,c,R ) Remember first character and go to the second part ( q 3 ,b ) = ( q bb ,d,R ) ( q 3 ,x ) = ( q scan ,x,R ) First part is consumed, check if there are chars at the second part ( q scan ,c ) = ( q scan ,c,R )Check if the second part is consumed ( q scan ,d ) = ( q scan ,d,R ) ( q scan , square ) = ( q accept , square...
View Full Document

This note was uploaded on 05/07/2010 for the course COMPUTER S 138 taught by Professor Icamarra during the Spring '10 term at UCLA.

Page1 / 5

hw7-answers - Solution to Homework 7 CS 321 1 Construct a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online