You are on page 1of 20

CSC 417: FORMAL MODELS OF COMPUTATION

Automata theory (also known as Theory of Computation) is a theoretical branch of Computer


Science and Mathematics, which mainly deals with the logic of computation with respect to simple
machines, referred to as automata. Automata enables the scientists to understand how machines
compute the functions and solve problems. The main motivation behind developing Automata Theory
was to develop methods to describe and analyse the dynamic behavior of discrete systems.
Automata can also be defined as a mathematical model and abstract model, which is used to detect
string in various languages. In Automata,
 Regular language is recognized by Finite state Automata
 Context Free language is recognized by Push down Automata
 Context sensitive language is recognized by linear bounded Automata
 Recursive Enumerable Language is recognized by Turing Machine.

Theory of Automata
Theory of automata is a theoretical branch of computer science and mathematical. It is the study of
abstract machines and the computation problems that can be solved using these machines. The abstract
machine is called the automata. The main motivation behind developing the automata theory was to
develop methods to describe and analyse the dynamic behaviour of discrete systems.
This automaton consists of states and transitions. The State is represented by circles, and the
Transitions is represented by arrows.
Automata is the kind of machine which takes some string as input and this input goes through a finite
number of states and may enter in the final state.
There are the basic terminologies that are important and frequently used in automata:
Symbols:
Symbols are an entity or individual objects, which can be any letter, alphabet or any picture.
Example:
1, a, b, #
Alphabets:
Alphabets are a finite set of symbols. It is denoted by ∑.
Examples:
∑ = {a, b}
∑ = {A, B, C, D}
∑ = {0, 1, 2}
∑ = {0, 1, ....., 5}

1
∑ = {#, β, Δ}
String:
It is a finite collection of symbols from the alphabet. The string is denoted by w. String: String is a
finite sequence of symbols from some alphabet. String is generally denoted as w and length of a string
is denoted as |w|.
Note: Σ* is set of all possible strings(often power set(need not be unique here or we can say multi set)
of string) So this implies that language is a subset of Σ*.
Empty string is the string with zero occurrence of symbols, represented as ε.
Number of Strings (of length 2)
that can be generated over the alphabet {a, b} -
- -
a a
a b
b a
b b
Length of String |w| = 2
Number of Strings = 4
For alphabet {a, b} with length n, number of
strings can be generated = 2n.
 Note – If the number of Σ’s is represented by |Σ|, then number of strings of length n, possible
over Σ is |Σ|n.

Example 1:
If ∑ = {a, b}, various string that can be generated from ∑ are {ab, aa, aaa, bb, bbb, ba, aba.....}.
 A string with zero occurrences of symbols is known as an empty string. It is represented by ε.
 The number of symbols in a string w is called the length of a string. It is denoted by |w|.
Example 2:
w = 010
Number of Sting |w| = 3
Language:

2
A language is a collection of appropriate string. A language which is formed over Σ can be Finite or
Infinite. A language is a set of strings, chosen from some Σ* or we can say- ‘A language is a subset
of Σ* ‘. A language which can be formed over ‘ Σ ‘ can be Finite or Infinite.
Example: 1
L1 = {Set of string of length 2}
= {aa, bb, ba, bb} Finite Language

Example: 2
L2 = {Set of all strings starts with 'a'}
= {a, aa, aaa, abb, abbb, ababb} Infinite Language

Finite Automata
Finite state Automata or Finite State Machine are the simplest model used in Automata. Finite state
automata accept regular language. The term finite means it has a limited number of possible states,
and number of alphabets in the strings are finite.
 Finite automata are used to recognize patterns.
 It takes the string of symbol as input and changes its state accordingly. When the desired
symbol is found, then the transition occurs.
 At the time of transition, the automata can either move to the next state or stay in the same
state.
 Finite automata have two states, Accept state or Reject state. When the input string is
processed successfully, and the automata reached its final state, then it will accept.
Formal Definition of FA
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
Examples:
The example of Finite state Automata is Automatic door controller because it has limited memory for
detecting the present state of the controller, automatic doors are often found at entrance and exists of
various hotels, supermarkets, theaters and hospitals etc. Automatic door have two pads that are used
for detection:

3
Front Pad: This is located at front of the doorway to detect the presence of the person.
Rear Pad: This pad is located at backside of the doorway. In this, controller hold the door to open till
the person passes all the way through it.

Important features of Finite Automata

Input: Finite Automata takes some input and with the use of this input we can produce some output.
The input of the automata is given in the input tape used in the automata. This tape is divided into cells
or squares which can hold one symbol at a time.
Output: Finite Automata produce some output with the use of some input.
States of Automata: Automata have finite number of input states. States of Automata like q0, q1…qn.
State Relation: State relations show how automata moves from one state to another state. The next
state of the automata at any instant of time is determined by the present state and the input.

4
Output Relation: The output of finite automata is related to either state only or both the inputs and
the states.
Advantages of finite Automata
Below are some advantages of Finite State Automata and Finite State Machine:
 Finite state machines are very flexible.
 Well suited for domains where execution time is shared between various modules.
 In finite state automata, we can easily determine the reachability of an input state whether it is
accepted or rejected.
Disadvantages of finite Automata
Below are some disadvantages of Finite State Automata and Finite State Machine:
 Finite state Automata have very limited amount of memory.
 Various multiplications operations on large numbers cannot be carried out on finite automata,
because it has limited memory and it cannot remember the full-length sequence of large
numbers.
 Not applicable for all types of applications.
 Finite state Automata cannot process Natural Language processes.
 Finite state automata have less computational power than some other models of computation
used in automata such as Push down Automata, linear bounded automata and Turing machine.
Applications of Finite Automata
Finite Automata is used in various fields like science, mathematics, and engineering. Below are some
applications of finite automata:
Finite state Automata used in Word Processor Programs to provide features, which allow us to search
for a given string.
 It is used in Digital Logic Design to control units for a disk or an Input/output controller on a
process.
 It is used in Lexical Analysis phase in complier design.
 It is used in various spell checker applications.
 It is used in various Circuit switching design.
 It is used in various text editors.

Finite Automata Model:


Finite automata can be represented by input tape and finite control.
Input tape: It is a linear tape having some number of cells. Each input symbol is placed in each cell.

5
Finite control: The finite control decides the next state on receiving particular input from input tape.
The tape reader reads the cells one by one from left to right, and at a time only one input symbol is
read.

Types of Automata:
There are two types of finite automata:
1. DFA(deterministic finite automata)
2. NFA(non-deterministic finite automata)

1. DFA
DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of the computation.
In the DFA, the machine goes to one state only for a particular input character. DFA does not accept
the null move.
2. NFA
NFA stands for non-deterministic finite automata. It is used to transmit any number of states for a
particular input. It can accept the null move.
Some important points about DFA and NFA:
1. Every DFA is NFA, but NFA is not DFA.

6
2. There can be multiple final states in both NFA and DFA.
3. DFA is used in Lexical Analysis in Compiler.
4. NFA is more of a theoretical concept.

Designing Deterministic Finite Automata


We will see some designing of Deterministic Finite Automata (DFA).
Problem-1: Construction of a DFA for the set of string over {a, b} such that length of the string |w|=2
i.e, length of the string is exactly 2.
Explanation – The desired language will be like:
L = {aa, ab, ba, bb}
The state transition diagram of the language will be like:

Here,
State A represent set of all string of length zero (0), state B represent set of all string of length one (1),
state C represent set of all string of length two (2). State C is the final state and D is the dead state it is
so because after getting any alphabet as input it will not go into final state ever.
Number of states: n+2
Where n is |w|=n
The above automata will accept all the strings having the length of the string exactly 2. When the
length of the string is 1, then it will go from state A to B. When the length of the string is 2, then it will
go from state B to C and when the length of the string is greater than 2, then it will go from state C to
D (Dead state) and after it from state D TO D itself.

Problem-2: Construction of a DFA for the set of string over {a, b} such that length of the string |w|>=2
i.e, length of the string should be at least 2.
Explanation – The desired language will be like:
L = {aa, ab, ba, bb, aaa, aab, aba, abb........}
The state transition diagram of the language will be like:

7
Here,
State A represent set of all sting of length zero (0), state B represent set of all sting of length one (1),
and state C represent set of all sting of length two (2).
Number of states: n+1
Where n is |w|>=n
The above automata will accept all the strings having the length of the string at least 2. When the length
of the string is 1, then it will go from state A to B. When the length of the string is 2, then it will go
from state B to C and lastly when the length of the string is greater than 2, then it will go from state C
to C itself.
Problem-3: Construction of a DFA for the set of string over {a, b} such that length of the string |w|<=2
i.e, length of the string is atmost 2.
Explanation – The desired language will be like:
L = {?, aa, ab, ba, bb}
The state transition diagram of the language will be like:

Here,
State A represent set of all sting of length zero (0), state B represent set of all sting of length one (1),
state C represent set of all sting of length two (2), state A, B, C is the final state and D is the dead state
it is so because after getting any alphabet as input it will not go into final state ever.
Number of states: n+2
Where n is |w|<=n
The above automata will accept all the strings having the length of the string at most 2. When the
length of the string is 1, then it will go from state A to B. When the length of the string is 2, then it will

8
go from state B to C and lastly when the length of the string is greater than 2, then it will go from state
C to D (Dead state).
Designing Non-Deterministic Finite Automata
Problem-1: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string
of the language starts with ‘a’.
Explanation: The desired language will be like:
L1 = {ab, abba, abaa, ...........}
Here as we can see that each string of the above language starts with ‘a’ and end with any alphabet
either ‘a’ or ‘b’.
But the below language is not accepted by this NFA because none of the string of below language
starts with ‘a’.
L2 = {ba, ba, babaaa..............}
The state transition diagram of the desired language will be like below:

In the above NFA, the initial state ‘X’ on getting ‘a’ as the input it transits to a final state ‘Y’. The final
state ‘Y’ on getting either ‘a’ or ‘b’ as the input it remains in the state of itself.

Problem-2: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string
of the language is not starting with ‘a’.
Explanation: The desired language will be like:
L1 = {ba, bba, bbaa, ...........}
Here as we can see that each string of the above language is not starting with ‘a’ but can end with
either ‘a’ or ‘b’.
But the below language is not accepted by this NFA because some of the string of below language
starts with ‘a’.
L2 = {ab, aba, ababaab..............}
The state transition diagram of the desired language will be like below:

9
In the above NFA, the initial state ‘X’ on getting ‘b’ as the input it transits to a final state ‘Y’. The
final state ‘Y’ on getting either ‘a’ or ‘b’ as the input it remains in the state of itself.

Transition Diagram
A transition diagram or state transition diagram is a directed graph which can be constructed as follows:
 There is a node for each state in Q, which is represented by the circle.
 There is a directed edge from node q to node p labeled a if δ(q, a) = p.
 In the start state, there is an arrow with no source.
 Accepting states or final states are indicating by a double circle.
Some Notations that are used in the transition diagram:

Fig. Notations

10
There is a description of how a DFA operates:
1. In DFA, the input to the automata can be any string. Now, put a pointer to the start state q and read
the input string w from left to right and move the pointer according to the transition function, δ. We
can read one symbol at a time. If the next symbol of string w is a and the pointer is on state p, move
the pointer to δ(p, a). When the end of the input string w is encountered, then the pointer is on some
state F.
2. The string w is said to be accepted by the DFA if r ∈ F that means the input string w is processed
successfully and the automata reached its final state. The string is said to be rejected by DFA if r ∉ F.
Example 1:
DFA with ∑ = {0, 1} accepts all strings starting with 1.
Solution:

The finite automata can be represented using a transition graph. In the above diagram, the machine
initially is in start state q0 then on receiving input 1 the machine changes its state to q1. From q0 on
receiving 0, the machine changes its state to q2, which is the dead state. From q1 on receiving input 0,
1 the machine changes its state to q1, which is the final state. The possible input strings that can be
generated are 10, 11, 110, 101, 111......., that means all string starts with 1.
Example 2:
NFA with ∑ = {0, 1} accepts all strings starting with 1.
Solution:

The NFA can be represented using a transition graph. In the above diagram, the machine initially is in
start state q0 then on receiving input 1 the machine changes its state to q1. From q1 on receiving input
0, 1 the machine changes its state to q1. The possible input string that can be generated is 10, 11, 110,
101, 111......, that means all string starts with 1.

11
Example 3:
Draw a deterministic and non-deterministic finite automate which accept 00 and 11 at the end of a
string containing 0, 1 in it, e.g., 01010100 but not 000111010.
Explanation – Design a DFA and NFA of a same string if input value reaches the final state then it is
acceptable otherwise it is not acceptable. NFA of the given string is as follows:

DFA of the given string is as follows:

Here, q0 shows the initial state, q1 and q2 are the transition states, and q3 and q4 are the final states.
Note – NFA and DFA both have same power that means if NFA can recognized an language L then
DFA can also be defined to do so and if DFA can recognized an language L then NFA can also be
defined to do so.
Example 4:
Draw a deterministic and non-deterministic finite automata which accept a string containing “the”
anywhere in a string of {a-z}, e.g., “there” but not “those”.
Explanation – Design a DFA and NFA of a same string if input value reaches the final state then it is
acceptable otherwise it is not acceptable. It is applicable for all the DFA and NFA. Since, NFA is quit
easier then DFA, so first make its NFA and then go through the DFA.
NFA of the given string is as follows:

12
DFA of the given string is as follows:

Here, q0 shows the initial state, q1 and q2 are the transition states, and q3 is the final state.

Example 5: Draw a deterministic and non-deterministic finite automata which accept a string
containing “ing” at the end of a string in a string of {a-z}, e.g., “anything” but not “anywhere”.
Explanation – Design a DFA and NFA of a same string if input value reaches the final state then it is
acceptable otherwise it is not acceptable. It is applicable for all the DFA and NFA. NFA of the given
string is as follows:

DFA of the given string is as follows:

13
Here, q0 shows the initial state, q1 and q2 are the transition states, and q3 is the final state.

Example 6: Draw a deterministic and non-deterministic finite automate which either starts with 01 or
end with 01 of a string containing 0, 1 in it, e.g., 01010100 but not 000111010.
Explanation – Draw a DFA and NFA of same language whose strings only reach to the final state
containing either 01 at start or at the end. If anything else is come then come out to the final state then
it does not accept. NFA of the given string is as follows:

DFA of the given string is as follows:

Here, q0 shows the initial state, q1, q2 are the transition states, and q3, q4, q5, q6, q7 are the transition
and final states.

14
Example 7: Draw a deterministic and non-deterministic finite automate which starts with 01 and ends
with 01 of a string containing 0, 1 in it, e.g., 01000101 but not 000111001.
Explanation – Draw a DFA and NFA of same language whose strings only reach to the final state
containing 01 at start and at the end. If anything else is come then come out to the final state then it
does not accept. NFA of the given string is as follows:

DFA of the given string is as follows

Here, q0 shows the initial state, q1, q2, q3 are the transition states, and q4, q5 are the transition and
final states.
Example 8: Draw a deterministic finite automata which recognize a string containing binary
representation 0, 1 in the form of multiple 2, e.g., 1010 but not 01101.
Explanation – Draw a DFA whose strings only reach to the final state containing 0 at the end that
means number is multiple of 2. If anything else is come then come out to the final state then it does
not accept. DFA of the given string is as follows:

Here, q0 shows the initial and final state, q1 is the transition states.

15
Difference between DFA and NFA
SR.NO. DFA NFA
1 DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
2 For each symbolic representation of the No need to specify how does the NFA
alphabet, there is only one state transition in react according to some symbol.
DFA.
3 DFA cannot use Empty String transition. NFA can use Empty String transition.
4 DFA can be understood as one machine. NFA can be understood as multiple little
machines computing at the same time.
5 In DFA, the next possible state is distinctly In NFA, each pair of state and input
set. symbol can have many possible next
states.
6 DFA is more difficult to construct. NFA is easier to construct.
7 DFA rejects the string in case it terminates in NFA rejects the string in the event of all
a state that is different from the accepting branches dying or refusing the string.
state.
8 Time needed for executing an input string is Time needed for executing an input string
less. is more.
9 All DFA are NFA. Not all NFA are DFA.
10 DFA requires more space. NFA requires less space then DFA.
11. Dead state may be required. Dead state is not required.
12. δ: QxΣ -> Q i.e. next possible state belongs δ: QxΣ -> 2^Q i.e. next possible state
to Q. belongs to power set of Q.

Pushdown Automata
We have already discussed finite automata. But finite automata can be used to accept only regular
languages. 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)

16
 q0 is the initial state
 Z is the initial pushdown symbol (which is initially present in stack)
 F is the set of final states
 δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*. In a given state, PDA will
read input symbol and stack symbol (top of the stack) and move to a new state and change the
symbol of stack.
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.
A ID is a triple (q, w, α), where:
1. q is the current state.
2. w is the remaining input.
3.α is the stack contents, top at the left.

Turnstile notation

⊢ sign is called a “turnstile notation” and represents one move.


⊢* sign represents a sequence of moves. e.g.- (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 ‘α’
Example : Define the pushdown automata for language {anbn | n > 0}
Solution : M = where Q = { q0, q1 } and Σ = { a, b } and Γ = { A, Z } and δ is given by :
δ( q0, a, Z ) = { ( q0, AZ ) }
δ( q0, a, A) = { ( q0, AA ) }
δ( q0, b, A) = { ( q1, ∈) }
δ( q1, b, A) = { ( q1, ∈) }
δ( q1, ∈, Z) = { ( q1, ∈) }
Let us see how this automata works for aaabbb.

17
Explanation : Initially, the state of automata is q0 and symbol on stack is Z and the input is aaabbb as
shown in row 1. On reading ‘a’ (shown in bold in row 2), the state will remain q0 and it will push
symbol A on stack. On next ‘a’ (shown in row 3), it will push another symbol A on stack. After reading
3 a’s, the stack will be AAAZ with A on the top. After reading ‘b’ (as shown in row 5), it will pop A
and move to state q1 and stack will be AAZ. When all b’s are read, the state will be q1 and stack will
be Z. In row 8, on input symbol ‘∈’ and Z on stack, it will pop Z and stack will be empty. This type of
acceptance is known as acceptance by empty stack.

Note :
 The above pushdown automaton is deterministic in nature because there is only one move from
a state on an input symbol and stack symbol.
 The non-deterministic pushdown automata can have more than one move from a state on an
input symbol and stack symbol.
 It is not always possible to convert non-deterministic pushdown automata to deterministic
pushdown automata.
 Expressive Power of non-deterministic PDA is more as compared to expressive deterministic
PDA as some languages which are accepted by NPDA but not by deterministic PDA which
will be discussed in next article.
 The push down automata can either be implemented using acceptance by empty stack or
acceptance by final state and one can be converted to another.

Let’s see the difference between Pushdown Automata and Finite Automata:
S.NO Pushdown automata finite automata
1. For Type-2 grammar we can design pushdown For Type-3 grammar we can design finite
automata. automata.

18
2. Non – Deterministic pushdown automata has Non-Deterministic Finite Automata has
more powerful than Deterministic pushdown same powers as in Deterministic Finite
automata. Automata.
3. Not every Non-Deterministic pushdown Every Non-Deterministic Finite Automata
automata is transformed into its equivalent is transformed into an equivalent
Deterministic pushdown Automata . Deterministic Finite Automata
4. Context free languages can be recognized by Regular languages can be recognized by
pushdown automata. finite automata.
5. Pushdown automata has the additional stack Finite Automata doesn’t has any space to
for storing long sequence of alphabets. store input alphabets.
6. It gives acceptance of input alphabets by going It accepts the input alphabets by going up
up to empty stack and final states. to final states.

Transition Table
The transition table is basically a tabular representation of the transition function. It takes two
arguments (a state and a symbol) and returns a state (the "next state").
A transition table is represented by the following things:
 Columns correspond to input symbols.
 Rows correspond to states.
 Entries correspond to the next state.
 The start state is denoted by an arrow with no source.
 The accept state is denoted by a star.
Example 1:

Solution:
Transition table of given DFA is as follows:
Present State Next state for Input 0 Next State of Input 1
→q0 q1 q2
q1 q0 q2

19
*q2 q2 q2
Explanation:
 In the above table, the first column indicates all the current states. Under column 0 and 1, the
next states are shown.
 The first row of the transition table can be read as, when the current state is q0, on input 0 the
next state will be q1 and on input 1 the next state will be q2.
 In the second row, when the current state is q1, on input 0, the next state will be q0, and on 1
input the next state will be q2.
 In the third row, when the current state is q2 on input 0, the next state will be q2, and on 1 input
the next state will be q2.
 The arrow marked to q0 indicates that it is a start state and circle marked to q2 indicates that it
is a final state.
Example 2:

Solution:
Transition table of given NFA is as follows:
Present State Next state for Input 0 Next State of Input 1
→q0 q0 q1
q1 q1, q2 q2
q2 q1 q3
*q3 q2 q2
Explanation:
 The first row of the transition table can be read as, when the current state is q0, on input 0 the
next state will be q0 and on input 1 the next state will be q1.
 In the second row, when the current state is q1, on input 0 the next state will be either q1 or q2,
and on 1 input the next state will be q2.
 In the third row, when the current state is q2 on input 0, the next state will be q1, and on 1 input
the next state will be q3.
 In the fourth row, when the current state is q3 on input 0, the next state will be q2, and on 1
input the next state will be q2.

20

You might also like