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

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

View Full Document Right Arrow Icon
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 0 , 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 a’s after b’s. 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 0 , a ) = ( q 1 , x, R ) Replace first char δ ( q 0 , b ) = ( q 3 , x, R ) δ ( q 1 , a ) = ( q 1 , a, R ) δ ( q 1 , b ) = ( q 3 , b, R ) Pass to b’s δ ( 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 0 , a ) = ( q 1 , y, R ) δ ( q 0 , 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
Image of page 1

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

View Full Document Right Arrow Icon
δ ( 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 , R ) Accept δ ( q scan , a ) = ( q restart , a, R ) No, try wxw after shifting x one square δ ( q scan , b ) = ( q restart , b, R ) δ ( q aa , a ) = ( q aa , a, R ) Control if second part’s first char is same δ ( q aa , b ) = ( q aa , b, R ) δ ( q bb , a ) = ( q bb , a, R ) δ ( q bb , b ) = ( q bb , b, R )
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern