SlideShare a Scribd company logo
1 of 79
PUSHDOWN
AUTOMATA AND
TURING MACHINES
UNIT IV
By Dr.T.p.Latchoumi
INTRODUCTION
 In the theory of computation, a branch of theoretical computer science a
Pushdown Automaton (PDA) is a type of automata that employs a stack.
 Pushdown automata are used in theories about what can be computed by
machines.
 They are more capable than finite-state machines but less capable than
Turing machines.
 Deterministic pushdown automata can recognize all deterministic
context-free languages while nondeterministic ones can recognize all
context-free languages, with the former often used in parser design.
CONT…
 A finite-state machine just looks at the input signal and the current
state: it has no stack to work with. It chooses a new state, the result of
following the transition.
 A PDA differs from a finite state machine in two ways:
 It can use the top of the stack to decide which transition to take.
 It can manipulate the stack as part of performing a transition.
CONT…
 If, in every situation, at most one such transition action is possible, then the automaton is
called a Deterministic Pushdown Automaton (DPDA).
 A given input string may drive a Nondeterministic Pushdown Automaton (NPA) to one of
several configuration sequences.
 If one of them leads to an accepting configuration after reading the complete input string.
 The latter is said to belong to the language accepted by the automaton.
 The following equation will help you to understand PDA,
 "Pushdown Automation" = "Finite State Machine" + "Stack”
A DIAGRAM OF A
PUSHDOWN
AUTOMATON
PDA has three
components
• An input tape
• A control unit
• A stack with infinite size.
EXPLANATION
 A PDA reads a given input string from left to right.
 In each step, it chooses a transition by indexing a table by
input symbol, current state, and the symbol at the top of the
stack.
 A PDA can also manipulate the stack, as part of performing
a transition.
 The manipulation can be to push a particular symbol to the
top of the stack, or to pop off the top of the stack.
 The automaton can alternatively ignore the stack, and leave
it as it is.
DEFINITIONS
•Thompson's Construction to
find out a Pushdown Automata is
a finite automata with extra
memory called stack, which
helps Pushdown automata to
recognize Context Free
Languages.
A Pushdown Automata (PDA)
can be defined as:
 Q is the set of states
 ∑is the set of input symbols
 Γ is the set of pushdown symbols (which can be pushed and popped
from stack)
 q0 is the initial state
 Z is the initial pushdown symbol (which is initially present in the
stack)
 F is the set of final states
 δ is a transition function which maps Q x {Σ ∪ ∈ } x Γ into Q x Γ*.
In a given state, the PDA will read input symbol and stock symbol
(top of the stack) and move to a new state and change the symbol of
stack.
GRAPHICAL
REPRESENTATION
OF PDA
 Transition diagram is the graphical representations of PDA in
which
 Nodes represent the states of PDA
 Start state is being indicated by an arrow
 Accepting states are indicated by double circles
 Arcs from one state to another state are labeled with input
and stack symbols.
 Arcs labeled with a,β|γ means that on input ‗a‘ the β on the
top of the stack has to be replaced by γ.
THEOREM
Equivalence of Regular
Expression and FA
INSTANTANEOUS DESCRIPTION (ID)
 Instantaneous Description (ID) is an informal notation of how a PDA ―computes‖ a input
string and make a decision that string is accepted or rejected.
An ID is a triple (q, w, α), where:
 q is the current state.
 w is the remaining input.
 α is the stack contents, top on the left.
TURNSTILE NOTATION
 ⊢ sign is called a ―turnstile notation‖ and represents one move.
 ⊢* sign represents a sequence of moves.
Eg- (p, b, T) ⊢ (q, w, α)
 This implies that while taking a transition from state p to state q, the input symbol ‗b‘ is consumed, and
the top of the stack ‗T‘ is replaced by a new string ‗α‘
LANGUAGES OF A
PUSH DOWN
AUTOMATA
CONT….
 A push down automata is similar to deterministic finite automata except that it has a few more properties
than a DFA.
 The data structure used for implementing a PDA is stack.
 A PDA has an output associated with every input.
 All the inputs are either pushed into a stack or just ignored.
 User can perform the basic push and pop operations on the stack which is used for PDA.
 One of the problems associated with DFAs was that could not make a count of the number of characters
which were given input to the machine.
 This problem is avoided by PDA as it uses a stack which provides us this facility also.
TERMINOLOGY
 Finite automata are highly standardized.
 There are many equivalent but different definitions of PDAs.
 The one we will use is a slight variant on the one described in Sipser.
 Sipser does not have a start stack symbol.
 Sipser does not allow transitions to push multiple symbols onto the stack.
 Feel free to use either this version or Sipser's; the two are equivalent to one another.
FINAL STATE ACCEPTABILITY
EMPTY STACK ACCEPTABILITY
EXAMPLE 1
Define the pushdown
automata for
language {anbn | n >
0}
Let us see how this
automaton works for
aaabbb.
Solution
 M = where Q = { q0, q1 } and Σ = { a, b } and Γ =
{ A, Z } and & delta is given by : &delta( q0, a, Z
) = { ( q0, AZ ) }
 &delta( q0, a, A) = { ( q0, AA ) }
 &delta( q0, b, A) = { ( q1, ε) }
 &delta( q1, b, A) = { ( q1, ε) }
 &delta( q1, ε, Z) = { ( q1, ε) }
EXAMPLE 2
Problem – Design a non
deterministic PDA for accepting
the language L ={w?{a,b}* | w
contains equal no. of a‘s and
b‘s}, i.e.,
L = {ab, aabb, abba, aababb,
bbabaa, baaababb, }
The number of a‘s and b‘s are
same in all the strings.
Stack transition functions-
CONT…
CONT……
EXAMPLE 3
CONT…
DIFFERENCE
BETWEEN DPDA
AND NPDA
EQUIVALENCE OF
PUSHDOWN
AUTOMATA AND
CFG
The goal is to prove that the following
three classes of the languages are all the
same class.
•The context-free languages (The
language defined by CFG‘s).
•The languages that are accepted by
empty stack by some PDA.
•The languages that are accepted by
final state by some PDA.
•If a grammar G is context-free, we can build an equivalent
nondeterministic PDA which accepts the language that is
produced by the context-free grammar G. A parser can be built
for the grammar G.
•Also, if P is a pushdown automaton, an equivalent context-free
grammar G can be constructed where L(G) = L(P)
•We will discuss how to convert from PDA to CFG and vice
versa.
FROM GRAMMAR
TO PUSHDOWN
AUTOMATA
 Step 1 − Convert the productions of the CFG into GNF.
 Step 2 − The PDA will have only one state {q}.
 Step 3 − The start symbol of CFG will be the start symbol in
the PDA.
 Step 4 − For non-terminal symbol, add the following rule:
 Step 5 - For each terminal symbols, add the following rule:
δ(q, a, a) = (q, ε) for every terminal symbol
Algorithm to find PDA
corresponding to a given CFG
Input − A CFG, G = (V, T, P, S)
Output − Equivalent PDA, P =
(Q, ∑, S, δ, q0, I, F)
EXAMPLE 1
EXAMPLE 2
EXAMPLE 3
CONT….
FROM PUSHDOWN
AUTOMATA TO
GRAMMAR
Algorithm to find CFG
corresponding to a given PDA
Input − A CFG, G = (V, T, P, S)
Output − Equivalent PDA, P =
(Q, ∑, S, δ, q0, I, F) such that the
non- terminals of the grammar
G will be {Xwx | w,x ∈ Q} and the
start state will be Aq0,F.
Step 1 − For every w, x, y, z ∈ Q, m ∈ S and a, b ∈ ∑, if δ (w, a,
ε) contains (y, m) and (z, b, m) contains (x, ε), add the
production rule Xwx → a Xyzb in grammar G.
Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx
→ XwyXyx in grammar G.
Step 3 − For w ∈ Q, add the production rule Xww → ε in
grammar G.
EXAMPLE 1
CONT…
EXAMPLE 2
CONT…
THEOREM
Equivalence of PDA
and Grammar
DIFFERENCE
BETWEEN PDA
AND FA
TURING
MACHINES (TM)
 A Turing Machine is an accepting device which accepts the
languages (recursively enumerable set) generated by type 0
grammars. It was invented in 1936 by Alan Turing.
 A Turing machine consists of a tape of infinite length on
which read and writes operation can be performed.
 The tape consists of infinite cells on which each cell either
contains input symbol or a special symbol called blank.
 It also consists of a head pointer which points to cell
currently being read and it can move in both directions.
WORKING
 A Turing Machine (TM) is a mathematical model which
consists of an infinite length tape divided into cells on
which input is given.
 It consists of a head, which reads the input tape.
 A state register stores the state of the Turing machine. After
reading an input symbol, it is replaced with another symbol,
its internal state is changed, and it moves from one cell to
the right or left. If the TM reaches the final state, the input
string is accepted, otherwise rejected.
DEFINITION
A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −
 Q is a finite set of states
 X is the tape alphabet
 ∑ is the input alphabet
 δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.
 q0 is the initial state
 B is the blank symbol
 F is the set of final states
COMPARISON
WITH THE
PREVIOUS
AUTOMATON
The following table shows a
comparison of how a Turing
machine differs from Finite
Automaton and Pushdown
Automaton.
EXAMPLE 1
EXAMPLE 2
The language L = {0n1n2n | n≥1}
represents a kind of language where we
use only 3 character, i.e., 0, 1 and 2.
In the beginning language has some
number of 0‘s followed by equal
number of 1‘s and then followed by
equal number of 2‘s.
Any such string which falls in this
category will be accepted by this
language.
The beginning and end of string is
marked by $ sign.
CONT…
EXAMPLE 3
CONT…
CONT….
NON-
DETERMINISTIC
TM
TURING
RECOGNIZABLE
TURING
DECIDABLE
DESCRIBING TM
CONT…..
PROGRAMMING
TECHNIQUES FOR
TURING MACHINE
 The input to a Turing machine is a string. Turing machines
themselves can be written as strings. Since these strings can
be used as input to other Turing machines.
 A universal Turing machine is one whose input consists of a
description M of some arbitrary Turing machine, and some
input w to which machine M is to be applied, we write this
combined input as M + w.
 This produces the same output that would be produced by
M. This is written as
 Universal Turing Machine (M + w) = M (w).
The Halting
Problem
THEOREM
Turing Machine ―Will Halt (M, w)‖ does not exist.
Proof: This theorem is proved by contradiction. Suppose we could build a machine
Will Halt‖. Then we can certainly build a second machine,
 ―LoopIfHalts‖, that will go into an infinite loop if and only if
 ―Will Halt‖ accepts its input:
 Function LoopIfHalts (M, w):
 if WillHalt (M, w) then while true do { } else
 return false;
 We will also define a machine ―LoopIfHaltOnItSelf‖ that, for any given input M, representing a
Turing machine, will determine what will happen if M is applied to itself, and loops if M will halt in
this case.
 Function LoopIfHaltsOnItself (M): return LoopIfHalts (M, M): Finally, we ask what happens if we
try:
 Function Impossible:
 return LoopIfHaltsOnItself (LoopIfHaltsOnItself):
 This machine, when applied to itself, goes into an infinite loop if and only if it halts when applied
to itself. This is impossible. Hence the theorem is proved.
IMPLICATIONS OF
HALTING
PROBLEM
Sometimes a meta-program‖ is used to
check another program for potential
infinite loops, and get this meta-program to
work most of the time. The theorem says
that we cannot ever write such a meta -
program and have it work all of the time.
This result is also used to demonstrate that
certain other programs are also impossible.
The basic outline is as follows:
i) If we could solve a problem X, we
could solve the Halting problem
ii) We cannot solving the halting
problem.
 Storage in the state
 We can make a state a tuple with a fixed number of fixed-size
components.
 Components of the tuple can hold a fixed amount of data to
simplify the behavior of a TM program.
 Multiple tracks
 We can make each symbol of the input alphabet a tuple with a fixed
number of fixed-size components.
 Components of the tuple can hold marks and other information to
indicate that an input tape square has been previously visited or has
been given some fixed value.
 Sets of states as subroutines
 We can group states into "subroutines" where a subroutine has its
own start state and another state which can serve as a "return" state
The following programming
techniques can be used to
make the behavior of a TM
clearer, but none of these
techniques adds any additional
computational power to a
basic TM
STORAGE IN
FINITE CONTROL
 A state register stores the state of the Turing machine. After
reading an input symbol, it is replaced with another symbol, its
internal state is changed, and it moves from one cell to the right
or left.
 If the TM reaches the final state, the input string is accepted,
otherwise rejected.
 The finite control can be used to hold a finite amount of
information.
 To do so, the state is written as a pair of elements, one
exercising control and the other storing a symbol.
 It should be emphasized that this arrangement is for conceptual
purposes only.
 No modification in the definition of the Turing machine has
been made.
EXAMPLE 1
Keep track of an additional
symbol:
If the extra data can be 𝐴 or 𝐵,
and the state can be 𝑞0 or 𝑞1,
then the actual states of the TM
can be {[𝑞0, 𝐴],[𝑞1, 𝐴],[𝑞0, 𝐵], [𝑞
1, 𝐵]}.
CONT….
EXAMPLE 2
Consider the Turing
machine
MULTIPLE
TRACKS
 Multitrack Turing machines, a specific type of Multi-tape Turing
machine, contain multiple tracks, but just one tape head reads and
writes on all tracks.
 Here, a single tape head reads n symbols from n tracks at one step.
It accepts recursively enumerable languages like a normal single-
track, single-tape Turing Machine accepts.
 Multi-track Turing machines is called as a unique type of Multi-
tape Turing machine.
 It consists of multiple tracks with one tape head reads and writes
on all tracks.
 But a single tape head reads n symbols from n tracks in a single
step.
DEFINITION
A Multitrack Turing machine can be formally described as a 6-
tuple (Q, X, ∑, δ, q0, F) where −
 Q is a finite set of states
 X is the tape alphabet
 ∑ is the input alphabet
 δ is a relation on states and symbols where
 δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,. ], Left_shift or
Right_shift)
 q0 is the initial state
 F is the set of final states
THEOREM
CONT…
EXAMPLE
CONT…
CONT…
CONT…
CHECKING OFF
SYMBOLS
CONT…
CONT…
EQUIVALENT
BETWEEN MULTI-
TAPE AND 1-TAPE
TM
CONT….
SUBROUTINE
 Just as complex programs are often broken down into
smaller functions and classes, complex TMs are often
broken down into smaller ―subroutines.
 A subroutine of a Turing machine is a small set of states in
the TM such that performs a small computation.
 ● Usually, a single entry state and a single exit state.
 ● Many very complicated tasks can be performed by TMs
by breaking those tasks into smaller subroutines.
CONT…
 Subroutines are extremely useful in standard programming
languages.
 They allow you to break a complex problem into simpler
and simpler sub problems.
 Standard Turing machines do not have subroutines, but it's
easy to fake them. We do not need to add any new features.
The basic idea is to use one state, or a small group of states,
to perform a single task
 Each subroutine performs some task that helps in the overall
task.
 The TM is then described by giving a collection of subroutines
and showing how they link up.
CONT…
In our TM, we need subroutines for the following:
 Copying the TM contents to another spot on the tape.
 Checking whether the number of 1's in that copy is a
multiple of the number of 0's in that copy (we already made
this!)
 Cleaning up the tape if the answer is no.
COPY
SUBROUTINE
CLEANUP
SUBROUTINE
EXAMPLE
For example, the following state can be used to find the left end of the input:
-------------------------------------------------------
q0 | a | a | L | q0
q0 | b | b | L | q0
q0 | # | # | R | q1
-------------------------------------------------------
This "subroutine" can be entered by going to state q0 (which isn't a problem) and it "exits" by
going to state q1 (which is a problem). We would like to have the subroutine exit to different
states, depending on where it was called from. The easy way to do this is to make multiple
copies of the subroutine, using the same structure but different state names, e.g.,
-------------------------------------------------------
q41 | a | a | L | q41
q41 | b | b | L | q41
q41 | # | # | R | q87
-------------------------------------------------------
This approach is cumbersome but theoretically adequate, so long as only a finite number of
copies are required.
Unit iv

More Related Content

What's hot

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture NotesFellowBuddy.com
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines constructionSampath Kumar S
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysisDattatray Gandhmal
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicLeyo Stephen
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Mohammad Ilyas Malik
 
3.1,2,3 pushdown automata definition, moves & id
3.1,2,3 pushdown automata   definition, moves & id3.1,2,3 pushdown automata   definition, moves & id
3.1,2,3 pushdown automata definition, moves & idSampath Kumar S
 

What's hot (20)

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Turing machines
Turing machinesTuring machines
Turing machines
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines construction
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministic
 
push down automata
push down automatapush down automata
push down automata
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
 
3.1,2,3 pushdown automata definition, moves & id
3.1,2,3 pushdown automata   definition, moves & id3.1,2,3 pushdown automata   definition, moves & id
3.1,2,3 pushdown automata definition, moves & id
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 

Similar to Unit iv

@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdfFariyaTasneem1
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introductionNAMRATA BORKAR
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptxssuser47f7f2
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! EdholeEdhole.com
 
deterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfdeterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfAmayJaiswal4
 
Theory of automata
Theory of automataTheory of automata
Theory of automataArslan905905
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Editor IJARCET
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Editor IJARCET
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,8neutron8
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptxThirumoorthy64
 

Similar to Unit iv (20)

@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introduction
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptx
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! Edhole
 
deterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfdeterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdf
 
Theory of automata
Theory of automataTheory of automata
Theory of automata
 
Turing machine by_deep
Turing machine by_deepTuring machine by_deep
Turing machine by_deep
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
flat unit1
flat unit1flat unit1
flat unit1
 
Automaton
AutomatonAutomaton
Automaton
 
Automata Theory - Turing machine
Automata Theory - Turing machineAutomata Theory - Turing machine
Automata Theory - Turing machine
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptx
 

More from TPLatchoumi (9)

Unit 3
Unit 3Unit 3
Unit 3
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Unit i
Unit iUnit i
Unit i
 
Unit ii
Unit iiUnit ii
Unit ii
 
Unit 1
Unit 1Unit 1
Unit 1
 
Unit v
Unit vUnit v
Unit v
 
Coa
Coa Coa
Coa
 
17 cs002
17 cs00217 cs002
17 cs002
 

Recently uploaded

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 

Recently uploaded (20)

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 

Unit iv

  • 2. INTRODUCTION  In the theory of computation, a branch of theoretical computer science a Pushdown Automaton (PDA) is a type of automata that employs a stack.  Pushdown automata are used in theories about what can be computed by machines.  They are more capable than finite-state machines but less capable than Turing machines.  Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design.
  • 3. CONT…  A finite-state machine just looks at the input signal and the current state: it has no stack to work with. It chooses a new state, the result of following the transition.  A PDA differs from a finite state machine in two ways:  It can use the top of the stack to decide which transition to take.  It can manipulate the stack as part of performing a transition.
  • 4. CONT…  If, in every situation, at most one such transition action is possible, then the automaton is called a Deterministic Pushdown Automaton (DPDA).  A given input string may drive a Nondeterministic Pushdown Automaton (NPA) to one of several configuration sequences.  If one of them leads to an accepting configuration after reading the complete input string.  The latter is said to belong to the language accepted by the automaton.  The following equation will help you to understand PDA,  "Pushdown Automation" = "Finite State Machine" + "Stack”
  • 5. A DIAGRAM OF A PUSHDOWN AUTOMATON PDA has three components • An input tape • A control unit • A stack with infinite size.
  • 6. EXPLANATION  A PDA reads a given input string from left to right.  In each step, it chooses a transition by indexing a table by input symbol, current state, and the symbol at the top of the stack.  A PDA can also manipulate the stack, as part of performing a transition.  The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack.  The automaton can alternatively ignore the stack, and leave it as it is.
  • 7. DEFINITIONS •Thompson's Construction to find out a Pushdown Automata is a finite automata with extra memory called stack, which helps Pushdown automata to recognize Context Free Languages. A Pushdown Automata (PDA) can be defined as:  Q is the set of states  ∑is the set of input symbols  Γ is the set of pushdown symbols (which can be pushed and popped from stack)  q0 is the initial state  Z is the initial pushdown symbol (which is initially present in the stack)  F is the set of final states  δ is a transition function which maps Q x {Σ ∪ ∈ } x Γ into Q x Γ*. In a given state, the PDA will read input symbol and stock symbol (top of the stack) and move to a new state and change the symbol of stack.
  • 8. GRAPHICAL REPRESENTATION OF PDA  Transition diagram is the graphical representations of PDA in which  Nodes represent the states of PDA  Start state is being indicated by an arrow  Accepting states are indicated by double circles  Arcs from one state to another state are labeled with input and stack symbols.  Arcs labeled with a,β|γ means that on input ‗a‘ the β on the top of the stack has to be replaced by γ.
  • 10. INSTANTANEOUS DESCRIPTION (ID)  Instantaneous Description (ID) is an informal notation of how a PDA ―computes‖ a input string and make a decision that string is accepted or rejected. An ID is a triple (q, w, α), where:  q is the current state.  w is the remaining input.  α is the stack contents, top on the left.
  • 11. TURNSTILE NOTATION  ⊢ sign is called a ―turnstile notation‖ and represents one move.  ⊢* sign represents a sequence of moves. Eg- (p, b, T) ⊢ (q, w, α)  This implies that while taking a transition from state p to state q, the input symbol ‗b‘ is consumed, and the top of the stack ‗T‘ is replaced by a new string ‗α‘
  • 12. LANGUAGES OF A PUSH DOWN AUTOMATA
  • 13. CONT….  A push down automata is similar to deterministic finite automata except that it has a few more properties than a DFA.  The data structure used for implementing a PDA is stack.  A PDA has an output associated with every input.  All the inputs are either pushed into a stack or just ignored.  User can perform the basic push and pop operations on the stack which is used for PDA.  One of the problems associated with DFAs was that could not make a count of the number of characters which were given input to the machine.  This problem is avoided by PDA as it uses a stack which provides us this facility also.
  • 14. TERMINOLOGY  Finite automata are highly standardized.  There are many equivalent but different definitions of PDAs.  The one we will use is a slight variant on the one described in Sipser.  Sipser does not have a start stack symbol.  Sipser does not allow transitions to push multiple symbols onto the stack.  Feel free to use either this version or Sipser's; the two are equivalent to one another.
  • 17. EXAMPLE 1 Define the pushdown automata for language {anbn | n > 0} Let us see how this automaton works for aaabbb. Solution  M = where Q = { q0, q1 } and Σ = { a, b } and Γ = { A, Z } and & delta is given by : &delta( q0, a, Z ) = { ( q0, AZ ) }  &delta( q0, a, A) = { ( q0, AA ) }  &delta( q0, b, A) = { ( q1, ε) }  &delta( q1, b, A) = { ( q1, ε) }  &delta( q1, ε, Z) = { ( q1, ε) }
  • 18. EXAMPLE 2 Problem – Design a non deterministic PDA for accepting the language L ={w?{a,b}* | w contains equal no. of a‘s and b‘s}, i.e., L = {ab, aabb, abba, aababb, bbabaa, baaababb, } The number of a‘s and b‘s are same in all the strings. Stack transition functions-
  • 24. EQUIVALENCE OF PUSHDOWN AUTOMATA AND CFG The goal is to prove that the following three classes of the languages are all the same class. •The context-free languages (The language defined by CFG‘s). •The languages that are accepted by empty stack by some PDA. •The languages that are accepted by final state by some PDA. •If a grammar G is context-free, we can build an equivalent nondeterministic PDA which accepts the language that is produced by the context-free grammar G. A parser can be built for the grammar G. •Also, if P is a pushdown automaton, an equivalent context-free grammar G can be constructed where L(G) = L(P) •We will discuss how to convert from PDA to CFG and vice versa.
  • 25. FROM GRAMMAR TO PUSHDOWN AUTOMATA  Step 1 − Convert the productions of the CFG into GNF.  Step 2 − The PDA will have only one state {q}.  Step 3 − The start symbol of CFG will be the start symbol in the PDA.  Step 4 − For non-terminal symbol, add the following rule:  Step 5 - For each terminal symbols, add the following rule: δ(q, a, a) = (q, ε) for every terminal symbol Algorithm to find PDA corresponding to a given CFG Input − A CFG, G = (V, T, P, S) Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F)
  • 30. FROM PUSHDOWN AUTOMATA TO GRAMMAR Algorithm to find CFG corresponding to a given PDA Input − A CFG, G = (V, T, P, S) Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F) such that the non- terminals of the grammar G will be {Xwx | w,x ∈ Q} and the start state will be Aq0,F. Step 1 − For every w, x, y, z ∈ Q, m ∈ S and a, b ∈ ∑, if δ (w, a, ε) contains (y, m) and (z, b, m) contains (x, ε), add the production rule Xwx → a Xyzb in grammar G. Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx → XwyXyx in grammar G. Step 3 − For w ∈ Q, add the production rule Xww → ε in grammar G.
  • 37. TURING MACHINES (TM)  A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turing.  A Turing machine consists of a tape of infinite length on which read and writes operation can be performed.  The tape consists of infinite cells on which each cell either contains input symbol or a special symbol called blank.  It also consists of a head pointer which points to cell currently being read and it can move in both directions.
  • 38. WORKING  A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into cells on which input is given.  It consists of a head, which reads the input tape.  A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input string is accepted, otherwise rejected.
  • 39. DEFINITION A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −  Q is a finite set of states  X is the tape alphabet  ∑ is the input alphabet  δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.  q0 is the initial state  B is the blank symbol  F is the set of final states
  • 40. COMPARISON WITH THE PREVIOUS AUTOMATON The following table shows a comparison of how a Turing machine differs from Finite Automaton and Pushdown Automaton.
  • 42. EXAMPLE 2 The language L = {0n1n2n | n≥1} represents a kind of language where we use only 3 character, i.e., 0, 1 and 2. In the beginning language has some number of 0‘s followed by equal number of 1‘s and then followed by equal number of 2‘s. Any such string which falls in this category will be accepted by this language. The beginning and end of string is marked by $ sign.
  • 52. PROGRAMMING TECHNIQUES FOR TURING MACHINE  The input to a Turing machine is a string. Turing machines themselves can be written as strings. Since these strings can be used as input to other Turing machines.  A universal Turing machine is one whose input consists of a description M of some arbitrary Turing machine, and some input w to which machine M is to be applied, we write this combined input as M + w.  This produces the same output that would be produced by M. This is written as  Universal Turing Machine (M + w) = M (w). The Halting Problem
  • 53. THEOREM Turing Machine ―Will Halt (M, w)‖ does not exist. Proof: This theorem is proved by contradiction. Suppose we could build a machine Will Halt‖. Then we can certainly build a second machine,  ―LoopIfHalts‖, that will go into an infinite loop if and only if  ―Will Halt‖ accepts its input:  Function LoopIfHalts (M, w):  if WillHalt (M, w) then while true do { } else  return false;  We will also define a machine ―LoopIfHaltOnItSelf‖ that, for any given input M, representing a Turing machine, will determine what will happen if M is applied to itself, and loops if M will halt in this case.  Function LoopIfHaltsOnItself (M): return LoopIfHalts (M, M): Finally, we ask what happens if we try:  Function Impossible:  return LoopIfHaltsOnItself (LoopIfHaltsOnItself):  This machine, when applied to itself, goes into an infinite loop if and only if it halts when applied to itself. This is impossible. Hence the theorem is proved.
  • 54. IMPLICATIONS OF HALTING PROBLEM Sometimes a meta-program‖ is used to check another program for potential infinite loops, and get this meta-program to work most of the time. The theorem says that we cannot ever write such a meta - program and have it work all of the time. This result is also used to demonstrate that certain other programs are also impossible. The basic outline is as follows: i) If we could solve a problem X, we could solve the Halting problem ii) We cannot solving the halting problem.
  • 55.  Storage in the state  We can make a state a tuple with a fixed number of fixed-size components.  Components of the tuple can hold a fixed amount of data to simplify the behavior of a TM program.  Multiple tracks  We can make each symbol of the input alphabet a tuple with a fixed number of fixed-size components.  Components of the tuple can hold marks and other information to indicate that an input tape square has been previously visited or has been given some fixed value.  Sets of states as subroutines  We can group states into "subroutines" where a subroutine has its own start state and another state which can serve as a "return" state The following programming techniques can be used to make the behavior of a TM clearer, but none of these techniques adds any additional computational power to a basic TM
  • 56. STORAGE IN FINITE CONTROL  A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left.  If the TM reaches the final state, the input string is accepted, otherwise rejected.  The finite control can be used to hold a finite amount of information.  To do so, the state is written as a pair of elements, one exercising control and the other storing a symbol.  It should be emphasized that this arrangement is for conceptual purposes only.  No modification in the definition of the Turing machine has been made.
  • 57. EXAMPLE 1 Keep track of an additional symbol: If the extra data can be 𝐴 or 𝐵, and the state can be 𝑞0 or 𝑞1, then the actual states of the TM can be {[𝑞0, 𝐴],[𝑞1, 𝐴],[𝑞0, 𝐵], [𝑞 1, 𝐵]}.
  • 59. EXAMPLE 2 Consider the Turing machine
  • 60. MULTIPLE TRACKS  Multitrack Turing machines, a specific type of Multi-tape Turing machine, contain multiple tracks, but just one tape head reads and writes on all tracks.  Here, a single tape head reads n symbols from n tracks at one step. It accepts recursively enumerable languages like a normal single- track, single-tape Turing Machine accepts.  Multi-track Turing machines is called as a unique type of Multi- tape Turing machine.  It consists of multiple tracks with one tape head reads and writes on all tracks.  But a single tape head reads n symbols from n tracks in a single step.
  • 61. DEFINITION A Multitrack Turing machine can be formally described as a 6- tuple (Q, X, ∑, δ, q0, F) where −  Q is a finite set of states  X is the tape alphabet  ∑ is the input alphabet  δ is a relation on states and symbols where  δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,. ], Left_shift or Right_shift)  q0 is the initial state  F is the set of final states
  • 73. SUBROUTINE  Just as complex programs are often broken down into smaller functions and classes, complex TMs are often broken down into smaller ―subroutines.  A subroutine of a Turing machine is a small set of states in the TM such that performs a small computation.  ● Usually, a single entry state and a single exit state.  ● Many very complicated tasks can be performed by TMs by breaking those tasks into smaller subroutines.
  • 74. CONT…  Subroutines are extremely useful in standard programming languages.  They allow you to break a complex problem into simpler and simpler sub problems.  Standard Turing machines do not have subroutines, but it's easy to fake them. We do not need to add any new features. The basic idea is to use one state, or a small group of states, to perform a single task  Each subroutine performs some task that helps in the overall task.  The TM is then described by giving a collection of subroutines and showing how they link up.
  • 75. CONT… In our TM, we need subroutines for the following:  Copying the TM contents to another spot on the tape.  Checking whether the number of 1's in that copy is a multiple of the number of 0's in that copy (we already made this!)  Cleaning up the tape if the answer is no.
  • 78. EXAMPLE For example, the following state can be used to find the left end of the input: ------------------------------------------------------- q0 | a | a | L | q0 q0 | b | b | L | q0 q0 | # | # | R | q1 ------------------------------------------------------- This "subroutine" can be entered by going to state q0 (which isn't a problem) and it "exits" by going to state q1 (which is a problem). We would like to have the subroutine exit to different states, depending on where it was called from. The easy way to do this is to make multiple copies of the subroutine, using the same structure but different state names, e.g., ------------------------------------------------------- q41 | a | a | L | q41 q41 | b | b | L | q41 q41 | # | # | R | q87 ------------------------------------------------------- This approach is cumbersome but theoretically adequate, so long as only a finite number of copies are required.

Editor's Notes

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.