180 likes | 269 Views
CSCI 2670 Introduction to Theory of Computing. October 5, 2004. Agenda. This week Turing machines Read section 3.1. Announcements. Tests will be returned tomorrow Tutorial sessions are suspended until further notice Extended office hours while tutorials are suspended Monday 11:00 – 12:00
E N D
CSCI 2670Introduction to Theory of Computing October 5, 2004
Agenda • This week • Turing machines • Read section 3.1 October 5, 2004
Announcements • Tests will be returned tomorrow • Tutorial sessions are suspended until further notice • Extended office hours while tutorials are suspended • Monday 11:00 – 12:00 • Tuesday 3:00 – 4:00 • Wednesday 3:00 – 5:00 October 5, 2004
Recap to date • Finite automata (both deterministic and nondeterministic) machines accept regular languages • Weakness: no memory • Pushdown automata accept context-free grammars • Add memory in the form of a stack • Weakness: stack is restrictive October 5, 2004
Turing machines • Similar to a finite automaton • Unrestricted memory in the form of a tape • Can do anything a real computer can do! • Still cannot solve some problems October 5, 2004
Control a b a ~ Touring machine schematic • Initially tape contains the input string • Blanks everywhere else (denoted ~ in class … different symbol in book) • Machine may write information on the tape October 5, 2004
Control a b a ~ Touring machine schematic • Can move tape head to read information written to tape • Continues computing until output produced • Output values accept or reject October 5, 2004
Control a b a ~ Touring machine schematic • Turing machine results • Accept • Reject • Never halts October 5, 2004
Differences between TM and FA • TM has tape you can read from and write to • Read-write head can be moved in either direction • Tape is infinite • Accept and reject states take immediate effect October 5, 2004
Example • How can we design a Turing machine to find the middle of a string? • If string length is odd, return middle symbol • If string length is even, reject string • Make multiple passes over string Xing out symbols at end until only middle remains October 5, 2004
Processing input • Check if string is empty • If so, return reject • Write X over first and last non-X symbols • After this, the head will be at the second X • Move left one symbol • If symbol is an X, return reject (string is even in length) • Move left one symbol • If symbol is an X, return accept (string is even in length) • Go to step 2 October 5, 2004
Example • 00110~ • First check if string is empty • X first and last non-X symbols • X011X~ • Move left one symbol • X011X~ • Is symbol an X? No • Move left one symbol • X011X~ • Is symbol an X? No • Write X over first and last non-X symbols October 5, 2004
Example • XX1XX~ • Move left one symbol • XX1XX~ • Is symbol an X? No • Move left one symbol • XX1XX~ • Is symbol an X? Yes • Return accept October 5, 2004
Formal definition of a TM Definition: A Turing machine is a 7-tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and • Q is the set of states, • is the input alphabet not containing the special blank symbol ~ • is the tape alphabet, where ~ and , • : QQ{L,R} is the transition function, October 5, 2004
Formal definition of a TM Definition: A Turing machine is a 7-tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and • q0Q is the start state, • qacceptQ is the accept state, and • qrejectQ is the reject state, where qrejectqaccept October 5, 2004
Computing with a TM • M receives input w = w1w2…wn* on leftmost n squares of tape • Rest of tape is blank (all ~ symbols) • Head position begins at leftmost square of tape • Computation follows rules of • Head never moves left of leftmost square of the tape • If says to move L, head stays put! October 5, 2004
Completing computation • Continue following transition rules until M reaches qaccept or qreject • Halt at these states • May never halt if the machine never transitions to one of these states! October 5, 2004
TM configurations • The configuration of a Turing machine is the current setting • Current state • Current tape contents • Current tape location • Notation uqv • Current state = q • Current tape contents = uv • Only ~ symbols after last symbol of v • Current tape location = first symbol of v October 5, 2004