Automata
Automata
Automata
Example 1 : Σ={ 0, 1 } 0110, 11, 001 are three strings over the binary alphabet Σ.
Given any alphabet Σ, the shortest string that can be formed from Σ is the empty
string, which we will write as ε. i.e., The length of empty string is | ε |=0
Palindrome: is one of property of string which string can be read same from
left to right as well as from right from left. For example: MadaM
ALPHABETS A N D
STRINGS
Powers of Alphabets
We write Σk (for some integer k) to denote the set of strings of length k with symbols from Σ. In
other words,
Σk= { w | w is a string over Σ and | w | = k}. Hence, for any alphabet, Σ 0 denotes the set of all strings
of length zero. That is, Σ0= {ε}.
Example 1: For the binary alphabet Σ={ 0,1 } we have the following.
Σ0={ε}. the set of all string of length 0,
Σ1= {0, 1},the set of all string of length 1,
Σ2= {00, 01,10,11},the set of all string of length 2,
Σ3= {000, 001, 010, 011, 100, 101, 110, 111}, the set of all string of length 3
The set of all strings over an alphabet is Σ denoted by Σ*. That is
Σ*=Σ0U Σ1U Σ2U Σ3U…. ΣnU…
Σ*={ε, 0, 1, 00, 01,1, 000, 001, 010, 011, 111,…}
ALPHABETS A N D
STRINGS
Relations on Strings
Substring: A string s is a substring of a string t iff s occurs contiguously as part of t.
Example: aaa is a substring of aaabbbaaa | aaaaaa is not a substring of aaabbbaaa
Proper substring: A string s is a proper substring of a string t iff s is a substring of t and s ≠ t.
Every string is a substring (although not a proper substring) of itself. The empty string, ε, is a
substring of every string.
Prefix: A string s is a prefix of t iff Ǝx ϵ Σ* (t = sx). Proper prefix: A string s is a proper prefix
of a string t iff s is a prefix of t and s ≠ t.
Every string is a prefix (although not a proper prefix) of itself. The empty string, ε, is a prefix of
every string. For example, the prefixes of abba are: ε, a, ab, abb, abba.
Suffix: A string s is a suffix of t iff Ǝx ϵ Σ* (t = xs). Proper suffix: A string s is a proper suffix
of a string t iff s is a suffix of t and s ≠ t.
Every string is a suffix (although not a proper suffix) of itself. The empty string, ε, is a suffix of every
string. For example, the suffixes of abba are: ε, a, ba, bba, abba.
LANGUAGE
Language is a (finite or infinite) set of strings over a finite alphabet Σ.
Let Σ = {a, b}. Σ * = {ε, a, b, aa, ab, ba, bb, aaa, aab, …}.
Some examples of languages over Σ are:
Ø, {ε}, {a, b}, {ε, a, aa, aaa, aaaa, aaaaa}, {ε, a, aa, aaa, aaaa, aaaaa, …}
Therefore, a language L is any subset of Σ*
The languages we consider for our discussion is an abstraction of natural languages. Our focus here
is on formal languages that need precise and formal definitions.
Formal language is a language designed for use in situations in which natural language is
unsuitable, as for example in mathematics, logic, or computer programming.
Formal Language(language) consists of strings whose symbols are taken from alphabet and are well
formed according to specific set of rules.
A formal language is the set of all strings permitted by the rules of formation. Based upon the set of
rules we can say that, given string is part of language or not.
LANGUAGE
Example: Σ1={a,b,c,….z): the set of small case letter in English.
Σ2={0,1,2,3…,9}: the set of decimal digits
Σ3 ={0,1}
L1 : The set of all string over Σ1, that contains the substring “at”. L1 ={cat, hat, mat, eat, ate, gate,….}
L3 : The set of all string that is in the form S#S where s is any string over Σ 1. L3 ={a#a, b#b, ab#ab,...}
Since left hand side of each production rule is the start symbol S and their right hand sides are
terminal strings, every derivation in G is of length one. In fact, we precisely have the following
derivation in G.
1. S ⇒ ab 2. S ⇒ bb 3. S ⇒ aba 4. S ⇒ aab
Hence, the language generated by G,
L(G) = {ab, bb, aba, aab}.
Notation: A → α1, A → α2 can be written as A → α1 | α2.
Grammar Types on the basis of production rule:
1. Type 0 - Unrestricted Grammar or Parse-Structure grammar
2. Type 1 - Context Sensitive Grammar
3. Type 2 - Context Free Grammar
4. Type 3 - Regular Grammar
α => β
Meaning of the double arrow ( => ) deriving β from the α in one step
α’ β’
Meaning of the double arrow star ( ) β’ obtained from the α’ in zero or most steps
Example:
S The man ate the fruit
- is called reflexive transitive closure of =>
FORMAL LANGUAGE
AUTOMATA
Automata: A algorithm or program that automatically recognizes if a particular string belongs to
the language or not, by checking the grammar of the string.
An automata is an abstract computing device (or machine).
An automaton is a, construct that possesses all the indispensable features of a digital computer. It
accepts the input, produces output, may have some temporary memory, and can make decisions
in transforming the input into the output.
AUTOMATA
Every Automaton fulfills the three basic requirements
Every automaton consists of some essential features as in real computers. It has a mechanism for
reading input. The input is assumed to be a sequence of symbols over a given alphabet and is
placed on an input tape(or written on an input file). The simpler automata can only read the input
one symbol at a time from left to right but not change. Powerful versions can both read (from left
to right or right to left) and change the input.
The automaton can produce output of some form. If the output in response to an input string is
binary (say, accept or reject), then it is called an accepter. If it produces an output sequence in
response to an input sequence, then it is called a transducer(or automaton with output).
The automaton may have a temporary storage, consisting of an unlimited number of cells, each
capable of holding a symbol from an alphabet ( which may be different from the input alphabet).
The automaton can both read and change the contents of the storage cells in the temporary storage.
The accusing capability of this storage varies depending on the type of the storage.
AUTOMATA
FINITE AUTOMATA (FA)
Finite Automata (FA)
Simplest form of an automation
It consists of only input tape and finite control unit not temporary storage
Tape has a read only head
Input tape is divided in to cells and each
cell can hold one symbol
It will read the left to right, it can read
one symbol at a time
While reading if it found no symbol then it stop the operation of automata
Control unit determines the state of the automata and control the movement of the head on the
input tape
It will accepts the regular languages
FINITE AUTOMATA (FA)
FA Definition
FA is a collection of 5-tuples (Q, Σ, δ,q0,F)
Q – finite set of states
Σ – finite input alphabet
δ – transition function or mapping
q0 – initial state, q0 ϵ Q
F – set of final state
Types of FA
Deterministic Finite Automata (DFA)
Nondeterministic Finite Automata (NFA)
FINITE AUTOMATA (FA)
Transition diagram:
Transition diagram is defined as collection of:
Finite set of states K
Finite set of symbols ∑
Non empty set S of K, S is called start state
Set of F of K, F is called final state
Transition function
S Final State
FINITE AUTOMATA (FA)
Examples 1:
Example 2:
FINITE AUTOMATA (FA)
Transition Table (Transition Matrix):
Tabular representation of the finite automata. For transition function is used
Example:
FINITE AUTOMATA (FA)
Transition Function:
Transition or Mapping function is denoted by δ. Two parameters are passed to this transition
function: one is current state and other is input symbol. The transition function returns a state which
can be called as next state.
For example
= δ (, a)
current state
a input
next state
FINITE AUTOMATA (FA)
Solved Problems for FA:
Example: Design a FA which accepts the only input 101 over the input set Z = { 0, 1}.
Problem statement is mentioned only input 101 will be accepted. So we can simply show the transition
diagram for the input.
Example: Design a FA which checks whether the given binary number is even.
Even any binary number ends with 0
Ex: 2 0010, 4 0100, 6 0110, 8 1000
Odd any binary number ends with 1
Ex: 1 0001, 3 0011, 5 0101, 7 0111
FINITE AUTOMATA (FA)
While designing FA, assume one start state, One state ending with
0 and another one ends with 1. we want to check whether the
given binary number is even or odd so fix the final state for 0 value.
Let take 2 sample inputs one odd and one even:
Case 1: For even number Case 2: For odd number
1000 => 1000 1011 => 1 011
=> 10 00 => 10 11
=> 100 0 => 101 1
=> 1000 => 1011
In case1: now at the end of input we are at final or accept state so its even number
In case2: now at the end of input we are at S1 state not in final state so its not even (odd) number
FINITE AUTOMATA (FA)
1. Design a FA which accepts only those strings which starts with 1 and ends with 0
2. Design FA which accepts even number of 0’s and even number of 1’s
3. Consider the given transition table and Find the language accepted by the finite automata
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )
The finite automata is called Deterministic Finite Automata if there is only one path for a specific
input from current state to next state.
From the given example transition diagram
From state for input ‘a’ there is only one path going to state .
Definition:
DFAdefinition is same as the finite automata
DFA is a five tuple notation denoted as: A = ( Q, ∑, δ, , F)
Q finite set of states
∑ finite set of input symbols
δ transition function
start state
F final state
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )
Example: Design a DFA which accepts string with even number 0’s and ends with single 1
over = { 0, 1 }. Give Transition table
Let take the sample strings:
1, 001, 00001, 0101, 001
will accepts the odd numbers of 0’s
will accepts the even number of 0’s
It should be followed by binary 1. so
will be final state.
Example: Design a DFA which accepts all the strings not having more than two a’s over = {a, b}.
From the problem statement DFA will accepts that strings contain maximum two a’s. if we try to accept
3rd a’s it will not lead as to final state.
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )
Transition table
Definition:
NFA formally defined as a collection of five tuple: A = ( Q, ∑, δ, , F)
Q finite set of states
∑ finite set of input symbols
δ transition function
start state (initial)
F set of final state
Example: Draw the transition diagram for NFA over { a, b } containing substring aabb.
Definition of Substring: Any string of consecutive symbols in some string is said to be a substring of
that string.
For example w = abbab u = bba
String ‘u’ is a substring of string ‘w’
D I F F E R E N C E B E T W E E N ( N FA ) A N D D FA
• DFA and NFA are both types of finite automata, which are theoretical
models used to describe and analyze the behavior of formal languages.
While they share some similarities, there are key differences between
the two:
• Deterministic Finite Automaton (DFA):
• Deterministic: In a DFA, for each input symbol, there is exactly one
transition from each state. This means that the next state is uniquely
determined by the current state and the input symbol.
• Single initial state: A DFA has a single initial state from which the
computation begins.
• No ε-transitions: DFA does not have ε-transitions, which are transitions
that can be taken without consuming any input symbol.
• No multiple outgoing transitions: From each state in a DFA, there can be
at most one transition for each input symbol. In other words, there are
no multiple outgoing transitions labeled with the same symbol.
D I F F E R E N C E B E T W E E N ( N FA ) A N D D FA
Example: Draw transition diagram for NFA over {0, 1} containing substring 01 and 10
This example is similar to previous Example :
Substring 01
Substring 10 1 0
Combine both:
=>
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )
Significance of NFA:
- DFA will produce the predictable output for the certain input
With out any input symbol from q state to p state transition is happened by ε
moves
Definition of ε – closure:
set of all states which are reachable from particular one state on ε –
transition.
Example : Find the ε – closure for the following NFA with ε
ε – closure() = {}
N FA E QU I VA L E N C E OF D FA & N FA
Example: Construct the DFA for the given NFA transition table.
From the given transition table:
left side and states are
available. In right side {, }
new state is available. For this
new state, we have to find the transition for new state {, } on each input {0, 1}
N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA
In the given NFA q is a final state so in DFA where ever exits that state become
3
final state of DFA.
N FA E QU I VA L E N C E OF D FA & N FA
Try yourself
1. Convert the given NFA to DFA
End of Chapter - 01
PROBLEMS
Solved Problems
1. Design a FA which accepts only those strings which starts with 1 and
ends with 0
2. Design FA which accepts even number of 0’s and even number of 1’s
3. Consider the given transition table and Find the language accepted
by the finite automata
Draw the transition diagram for the given transition table
It will accepts the even no of 1’s and even no of 0’s. for example: strings
are: 0011, 1010. 1001, 111100, etc.,
4. Draw the transition diagram and table for NFA in which double 1 is
followed by double 0 over { 0, 1 }.
Finite Automata for double 1
Sample input string: 00, 000, 100, 0000, 0100, 000, 001, 0001, 0010
6. Design NFA accepting all strings end with 01, over ∑ = {0, 1}
Automata for 01