Finite Automata and Formal Language (19CS3501) : Department of Computer Science
Finite Automata and Formal Language (19CS3501) : Department of Computer Science
Finite Automata and Formal Language (19CS3501) : Department of Computer Science
String
• It is finite collection of symbols from alphabet.
• For example, if ∑ = {a,b} then various strings that can be formed
from ∑ are {ab, ba, aaa, bbbb, aba, bab, ….}. An infinite number of
strings can be generated.
Empty String
• String with zero occurrence of symbol. Empty string denoted by є
•
•
Examples
• The set of all strings over {a,b,c} that have ac as substring can be
▪ Input alphabet ∑ = {a,b,c}
▪ String = {ac, aac, aca, bac, acb, cac, acc, aaca, aacb, aacc,
baca, bacb, back, caca, cacb, cacc, aaac, abac, acac, baac,
bbac, bcac, caac, cbac, ccac, acaa, acab, acba, acbb, acbc,
acca, accb,
∈
accc,…..}
▪ Language L = {xacy | x,y ∈{a,b,c}∗}
• The set of all strings over {0,1} that start with 0’s can be
▪ Input alphabet ∑ = {0,1}
▪ String = {0, 00, 01, 001, 010, 000, 011, 0000, 0111, 0101,
0010……}
▪ Language L = {0x | x ∈{0,1}*}
Examples
•
Finite State Machine / Finite Automata
• The finite state machine represents a mathematical model that used
to recognize patterns
• It takes string as input, move to next state according to the current
input symbol and current state and generate accept or reject as
output
• At the end of string if we are at the final state that means string is
valid or accepted otherwise invalid or rejected.
• The input is processed by various states.
▪ initial state or start state
▪ intermediate states
▪ final or accept state
• The finite state system is very good design tool for the programs
such as TEXT EDITORS and LEXICAL ANALYZERS.
Definition of Finite Automata
• A finite automata is a collection of 5-tuple(Q,∑,δ,q0,F) Where ,
▪ Q is finite set of states, which is non empty.
▪ ∑ is input alphabet, indicates input set.
▪ δ is transition function or mapping function. We can
determine the next state using this function.
▪ q0 is an initial state and q0 є Q
▪ F is set of final states. F є Q
Finite Automata Model
• The finite automata can be
represented as
❖ Input Tape – It is a linear tape having
some number of cells. Each input symbol
is placed in each cell
❖ Finite Control – Finite control decides
the next state on receiving particular
input from input tape
❖Tape Reader – It reads the cell one by
one from left to right, at a time only one
input is read
Deterministic Finite Automata (DFA)
The Finite Automata is called Deterministic Finite Automata if
there is only one path for a specific input from current state to
next state. It can be represented as follows:
• A machine M = (Q,∑,δ,q0,F) Where ,
▪ Q is finite set of states, which is non empty.
▪ ∑ is input alphabet, indicates input set.
▪ δ is transition function or mapping function. We can
determine the next state using this function.
δ : Q x ∑ -> Q
▪ q0 is an initial state and is in Q
▪ F is set of final states.
Non-Deterministic Finite Automata (NFA)
•
Difference Between DFA and NFA
Representation of Machine
• Transition Diagram or State Diagram: A DFA is represented by
digraphs called state diagram.
▪ For each state in Q, there is a node.
▪ For each state q in Q, input symbol a in ∑. Let δ(q,a) = p then
there is a arc from node q to node p labelled by a.
▪ The initial state is denoted by an empty single incoming arc.
▪ Nodes corresponding to final state denoted by double circle
Notation for constructing transition diagram
When machine accept
• Initial state is indicated by single arrow null or empty string
q
q0 0
1 0 0
1 0,1
q5
0,1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2,q3,q4,q5} State/Input 0 1
▪ ∑ = {0,1} q0 q1 q5
▪ q0 is initial state q1 q2 q5
▪ F = {q4} q2 q5 q3
▪ δ is define as table: q3 q5 q4
*q4 q5 q5
q5 q5 q5
Construct DFA which accept string start with 0 and end with 1
• String = {01,001,011,0001,0011,0101,0111……}
• Language L = {0x1| x∈{0,1}∗} 0
1
1
q 0 q
q2
q2
0 1
0
1 q
3
0,1
q a,b
2
a,b
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2}
State/Input a b
▪ ∑ = {a,b}
q0 q1 q1
▪ q0 is initial state
*q1 q2 q2
▪ F = {q1} q2 q2 q2
▪ δ is define as table:
Construct DFA which accept string starting with string ab
• String = {ab,aba,abb,abaa,abab,abba,abbb……}
• Language L = {abx | x є (a+b)*} a b
q0 q1 q2 a,b
b
a
q3 a,b
▪ ∑ = {0,1} q1 q2 q3
▪ F = {q2,q4} q3 q1 q4
q3 0,
1
• DFA is define as M = (Q,∑,δ,q0,F) Where
State/Input 0 1
▪ Q = {q0,q1,q2,q3}
q0 q1 q1
▪ ∑ = {0,1}
q1 q3 q2
▪ q0 is initial state *q2 q2 q2
▪ F = {q2} q3 q3 q3
▪ δ is define as table:
Construct DFA which accept string having even no of 0’s and even
no of 1’s
•
State/Input 0 1
q0* q1 q3
q1 q0 q2
q2 q3 q1
q3 q2 q0
Construct DFA which accept strings of {a,b} such that length of the
string is divisible by 3
• String = {є,aaa,aab,aba,abb,baa,bab,bba,bbb,aaaaaa,
aaaaab……..}
a,
• Language L = {((a+b)(a+b)(a+b))*} 0 b 1
a,
b 2
a,
b
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2} State/Input a b
q0* q1 q1
▪ ∑ = {a,b}
q1 q2 q2
▪ q0 is initial state q2 q0 q0
▪ F = {0}
▪ δ is define as table:
Construct DFA which accept strings such that number of 0’s
divisible by 2 and number of 1’s divisible by 3.
•
1 1
00 01 02
1
0 0 0 0
0
0
1 1
10 11 12
1
Construct DFA which accept strings of decimal number
• String = {0.23,1.333,4.555333,…………..} 0-9
0-9
• Language L = {x.x |xє{0-9}+} 0-9 . 0-9 q
q q q
0 1 2 3
1,4,7 q
q0
1
2,5,8
1,4,7
2,5,8
2,5,8
1,4,7
q
2
0,3,6,9