Finite Automata: Anab Batool Kazmi
Finite Automata: Anab Batool Kazmi
Finite Automata: Anab Batool Kazmi
.
• An alphabet Σ of possible input letters.
• Finite set of transitions which tells which state
to move.
Finite Automata
Finite Automata
Non
deterministic Mealy Machine
Finite Automata
Deterministic
Moore Machine
Finite Automata
Categories of Finite Automata
Two Categories
• Deterministic Finite Automata (DFA)
– The machine can exist in only one state at any
given time.
• Non Deterministic Finite Automata (NFA)
– The machine can exist in multiple states at the
same time.
Non Deterministic Finite Automata
Non Deterministic Finite Automata
• Nondeterminism gives a machine multiple
options for its moves.
• In NFA given the current state there could be
multiple next states.
• The next state may be chosen at random.
• All the next states may be chosen at parallel.
NFA
• In a nondeterministic finite automaton (NFA),
for each state there can be zero, one, two, or
more transitions corresponding to a particular
symbol.
• If NFA gets to start with more than one
possible transition corresponding to the input
symbol, we say it branches.
Non Deterministic Finite Automaton
- +
- a,b +
R.E=ab b
- a b +
Examples NFA
All strings that ends with a. if Σ={a,b}
R.E=(a+b)* a
NFA:
a
a,b - +
Theory of Automata 15
Example
• One of many FAs that accept all words is
• Here, the ± means that the same state is both a start and a final
state.
• The language for this machine is
(a + b)*
Theory of Automata 16
Examples NFA
• All strings that starts with a and ends with bb .
. when Σ={a,b}
R.E=a(a+b)*bb + ^
NFA:
-
a b b +
2 3 4
+
a,b
Examples NFA
• All strings that starts and ends with same
letter. when Σ={a,b}
R.E= a(a+b)*a + b(a+b)*b
a,b
NFA:
- a a +
b b
a,b
Examples NFA
• All strings that starts and ends with different
letter. when Σ={a,b}
R.E= a(a+b)*b + b(a+b)*a
a,b
NFA:
- a 1 b +
b a
2
a,b
Examples NFA
• All strings that contain aa. when Σ={a,b}
R.E= (a+b)*aa (a+b)*
NFA:
a,b a,b
- a a +
Examples NFA
• All strings of even length when Σ={a}
R.E= (aa)*
-
+
a
All strings of even length when null is not
included Σ={a}
• R.E =(aa).(aa)*
a
a a
-
+
a
Examples NFA
• All strings having even no. of b’s and any no of
a . And null is included. when Σ={a,b}
R.E= a* (b a* b)* a*
b
a
-
+ a
b
Examples NFA
• All strings of length 2 when Σ={0,1}
R.E= (0+1)(0+1)
0 0
-
+
1 1
- 0,1 0,1 +
Examples NFA
• All strings multiple of 3.
• R.E= ((a+b)(a+b)(a+b))*
- a,b a,b
+
a,b
Examples NFA
• All strings that contain atleast one a and end
with b.
R.E= (a+b)*a(a+b)*b
a,b
a,b
- a b +
Example NFA of Numeric Literals
• describe the language of numeric “literals,”
which typically includes strings such as 14, +1,
−12, 14.3, −0.99, 16.0, 3E14, −1.00E2, 4.1E−1,
and 0.3E+2.
• d=0 + 1 + 2 + ·· ·+9
• s=( ^ ) + (+) + ( - )
• p= .
• R.E=sdd∗( ^+ pd∗d)(^ + Esd∗d)
14E8, +16E-9, 16.23E-21
• d=0 + 1 + 2 + ·· ·+9
• s=( ^ ) + (+) + ( - )
• p= .
s d p d
- 3 +
2 4
1 + 5
^ E
^
S
d
d
+ 7
8
a b b a,b
- +
2 3 4
1 5
b a
a
a,b
6 b
a L={abbb,abba,baab,babb}
D
7
a,b
a
a,b
a,b
b
+
8
9
When the string is acceptable by NFA?
• If there is any way to run the machine that ends in any set
of states out of which one state is the final state, then
the NFA accepts.
• An NFA accepts a string x if it can get to an accepting state
on input x.
– Think of it as trying many options in parallel, and hoping one
path gets lucky
–Transition Q × ∑ → ϕ is possible
– the NFA treats this as a rejecting path (the string may still reach
an accepting state by another path)
– A convenient shortcut for our “hell/rejection/black-hole” state
NFA accepting a string
• Q={A,B} 0
In the end we are in
• qo= A 0 state A or B and B is
• δ= A B accepting state. So
–Ax0→A 100 is accepted.
–Ax0→B
–Ax1→A
ϕ
–Bx0→ϕ
A B
–Bx1→ϕ
NFA not accepting a string
• Q={A,B} 0
In the end we are in
• qo= A state A or ϕ and both
• δ= A B are not at all
–Ax0→A accepting states. So
1 01 is not accepted.
–Ax0→B
–Ax1→A
A ϕ
–Bx0→ϕ
–Bx1→ϕ
Deterministic Finite Automata
Deterministic Finite Automata
• R.E=((a+b)(a+b))*
• Q={x,y}
• qo=x
• A=x
Strings starting with b
The language L of strings,
defined over Σ={a, b},
starting with b.
R.E: b (a+b)*
• Q={A,B,1}
• qo=A Old States
New States
Reading Reading
• A={B}
a b
1
A- B
B
• R.E=(a+b)* a
• Q={1,2} New States
• qo=1
Old States Input Input
a b
1- 2 1
2+ 2 1
• A=2
Beginning with and ending in same
letters.
the Language L of Strings
of length two or more,
defined over Σ = {a, b},
beginning with and
ending in same letters.
• R.E=
a (a+b)* a + b (a+b)* b
• Q={1,2,3,4,5} Old States Input
a
New States
Input
b
• qo=1
1- 2 3
2 4 2
3 3 5
• A={4,5}
4+ 4 2
5+ 3 5
beginning with and ending in different
letters
the Language L of Strings,
defined over Σ = {a, b},
beginning with and
ending in different letters.
• R.E=a (a+b)* b + b
(a+b)* a
• Q={1,2,3,4,5} Old States Input
New States
Input
• qo=1
a b
1- 2 3
2 2 4
3 5 3
• A={4,5}
4+ 2 4
5+ 5 3
String containing double a
The Language L of strings ,
defined over Σ = {a, b},
containing double a.
• R.E=(a+b)* aa (a+b)*
• Q={1,2,3}
New States
1-
Input
a
2
Input
b
1
2 3 1
• A=3
3+ 3 3
having double 0’s or double 1’s,
The language L of strings,
defined over Σ={0, 1},
having double 0’s or double
1’s,
• R.E=(0+1)* (00+11)
(0+1)*
• Q={A,B,x,y} Old States Input
New States
Input
0 1
• qo=A A-
x
y
x
B
x
y
y
B
• A=B
B+ B B
Having triple a’s or triple b’s.
• R.E=(a+b)* (aaa+bbb)
(a+b)* New States
1-
Input
a
2
Input
b
3
• qo=1
2 4 3
3 2 5
4 6 3
• A=6
5 2 6
6+ 6 6
L = {Λ, b, ab, bb}
L = {Λ, b, ab, bb}, defined
over Σ ={a, b},
• R.E=Λ + b + ab + bb OR
• R.E= Λ + b (Λ + a + b)
• Q={1,2,3,4,5} Old States Input
New States
Input
a b
• qo=1 1±
2+
3
3
x
y
2
5
4
4+ y y
• A={1,2,4,5} 5+
x
y
x
x
y
x
x
y
• R.E=(ab+ba)(ab+ba)*
a
a a
b a
- + b D
b
a
b b
a
b
Don’t Ends at Example
For such conditions some times it is difficult to
make direct DFA, So we have an alternative
• First make DFA for “ends at”
• Then Convert all non accepting states to
accepting states and vice versa
Don’t End at ab
• Don’t Ends at ab
• Ends at ab • R.E=(a+b)*(aa+ba+bb)
• R.E=(a+b)*ab
a
a
a
a - a
+
a b +
- +
b
b
b
b
Don’t Ends at bba
• Ends at bba • Don’t ends at bba
• R.E=(a+b)*bba
b b
a
b b a - b b a
- + + +
+
a a
a a