1. Dete rministic Finite
Autom ata (DFA)
โข DFA can be defined by quintuples
( ๐ , ฮฃ , ๐ฟ , ๐ 0 , ๐น )
โ ๐ is finite set of states
โ ฮฃ is finite set of alphabets
โ ๐ฟ is transition function
โ ๐ 0 is initial state
โ ๐น finite set of final states
1
3. Transition Function
๐ฟ: ๐ ฮง ฮฃ โ ๐
{A, B, C} X {a, b} ๏ {A, B, C}
(A, a)
(A, b)
(B, a)
(B, b)
(C, a)
(C, b)
A
B
C
For every input on a
state there is
exactly one
transition.
3
A
B
C
4. Question
โข Why this FA is called Deterministic Finite
Automata?
โ Every state on seeing any input it is always going
to go to only one state.
4
5. DFA
โข Construct a DFA, that accepts set of all strings
over {a, b} of length 2.
โข Ans:
โ ฮฃ = ๐, ๐
โ ๐ฟ = {๐๐, ๐๐, ๐๐, ๐๐}
B C
A
a a
5
6. DFA
โข Is this a complete DFA?
โข No
โข Now is this a complete DFA?
โข No
โข After reaching sate โDโ we canโt go back to the final state, that is
why this state is called dead state/trap state.
B C
A
a a
B C
A
B C
A
a, b a, b
a, b a, b
D
a, b
a, b
6
7. Acceptance
โข Acceptance of a string by a FA:
โ Scan the entire string and if we reach a final state
from initial state.
โข Acceptance of a language by a FA:
โ If all the strings in the language are accepted by
the FA and all the strings those are not in the
language must reject by the FA.
7
8. DFA
โข Construct a DFA that accept all strings over the
alphabets {a, b} where the string length is at least 2.
โ ๐ โ ๐, ๐ and ๐ โฅ ๐
โ ๐ฎ = ๐, ๐
โ ๐ณ = {๐๐, ๐๐, ๐๐, ๐๐, ๐๐๐, โฆ โฆ ๐๐๐, โฆ โฆ โฆ }
โ Up to this is a DFA of string length 2. This is not the
required DFA.
โ Now this is required DFA.
A B
a,b
C
a,b
a, b
8
9. DFA
โข Construct a DFA that accept all strings over the
alphabets {a, b} where the string length is at most
two.
โ ๐ โ ๐, ๐ and ๐ โค ๐
โ ๐ฎ = ๐, ๐
โ ๐ณ = {๐, ๐, ๐, ๐๐, ๐๐, ๐๐, ๐๐}
โ To accept null string (๐) the only way to make initial
state to both initial state and final state.
A B
a,b
C
a,b
D
a, b
a, b
9
10. Minimum numbe r of state s
๐ = ๐ ๐ โฅ ๐ ๐ โค ๐
๐ = ๐
n + 2
๐ โฅ ๐
n + 1
๐ โค ๐
n + 2
10
11. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where the string length is
divisible by two.
โข ๐ณ = {๐, ๐๐, ๐๐, ๐๐, ๐๐, ๐๐๐๐ โฆ ๐๐๐๐ โฆ โฆ โฆ }
โข This is not a finite automata
A B
a, b
C
a, b
D
a, b
E
a, b
Length 0 Length 1 Length 2 Length 3 Length 4
11
12. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where the string length is
divisible by two.
โข This is not minimal
A B
a, b
C
a, b
Length 0 Length 1 Length 2
A B
a, b
Length
Even
Length
Odd
a, b
a, b
12
13. DFA
โข Construct a DFA that accept all strings over the
alphabets {a, b} where the string length is not
divisible by two.
โข We will get 0 or 1 after diving the length of a string
by two. That is why we need two state.
โข If string length is 3 then we will get 0 or 1 or 2 as
remainder after dividing any length by 3. So we will
be requiring three state in that case.
A B
a, b
Length
Even
Length
Odd
a, b
13
14. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where the string length is
divisible by three.
โ ๐ ๐๐๐ 3 = 0
โ ๐ฟ = {๐, ๐๐๐, โฆ โฆ โฆ , ๐๐๐, ๐๐๐๐๐๐, โฆ โฆ โฆ , ๐๐๐๐๐๐, โฆ โฆ โฆ โฆ โฆ โฆ }
A B
a, b
C
a, b
Length
0,3,6,โฆ
Length
1,4,7,โฆ
Length
2,5,8,โฆ
a, b
14
15. DFA
โข Construct a DFA where ๐ โ 1 ๐๐๐ 3
โข ๐ โ 1 ๐๐๐ 3 means ๐ ๐๐๐ 3 = 1
โข For ๐ ๐๐๐ ๐ = 0 ๐๐ ๐ โ ๐ ๐๐๐ n (m is any number)
in general for minimal DFA we need ๐ number of states.
A
a, b
C
a, b
Length
0,3,6,โฆ
Length
1,4,7,โฆ
Length
2,5,8,โฆ
a, b
B
15
16. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string is two.
โ ๐๐ ๐ = 2
โ ๐ฟ = ๐๐, ๐๐๐, ๐๐๐, ๐๐๐, ๐๐๐๐, โฆ โฆ โฆ
B
a
C
a
0 โaโs 1 โaโs 2 โaโs
A D
b b b
a
3 โaโs
a,b
16
17. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string at least two.
โ ๐๐ ๐ โฅ 2
B
a
C
a
0 โaโs 1 โaโs 2 โaโs
A
b b a, b
17
18. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string at most two.
โ ๐๐ ๐ โค 2
b
B
a
C
a
0 โaโs 1 โaโs 2 โaโs
A
b b
D
3 โaโs
a,b
a
18
19. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string is even.
โ ๐๐ ๐ ๐๐๐ 2 = 0
โ ๐๐ ๐ โ 0 ๐๐๐ 2
A B
a
Length
Even
Length
Odd
a
b
b
19
20. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string is odd.
โ ๐๐ ๐ ๐๐๐ 2 = 1
โ ๐๐ ๐ โ 1 ๐๐๐ 2
b
A B
a
Length
Even
Length
Odd
a
b
20
21. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ in
the string is divisible by 3.
โ ๐๐ ๐ ๐๐๐ 3 = 0
โ ๐๐ ๐ โ 0 ๐๐๐ 3
A B
a
a
b
b
C
a
b
21
22. DFA
โข ๐๐๐๐ ๐ โ ๐ ๐๐๐ n , how to draw DFA??
โ ๐ number of states will be there
โข If k=0 ๐0 will be final state
โข If k=1 ๐1 will be final state
โข If k=2 ๐2 will be final state
โข If k=3 ๐3 will be final state
โข So on
22
23. Assignment
1. Construct a DFA that accept all strings over the
alphabets {a, b} where number of โbโ in the string is
divisible by 5.
2. Construct a DFA that accept all strings over the
alphabets {a, b} such that ๐๐ ๐ โ 2 ๐๐๐ 5
3. Construct a DFA that accept all strings over the
alphabets {a, b} such that ๐๐ ๐ โ 1 ๐๐๐ 3
23
24. DFA
โข Construct a DFA that accept all strings over
the alphabets {a, b} where number of โaโ and
number of โbโ in the string is even.
โ ๐๐ ๐ ๐๐๐ 2 = 0 & ๐๐ ๐ ๐๐๐ 2 = 0
โ ๐๐ ๐ โ 0 ๐๐๐ 2 & ๐๐ ๐ โ 0 ๐๐๐ 2
๐๐ ๐ ๐๐ ๐
E E
O E
E O
O O
Four possible
states
representing this
situation
24
25. DFA
ee eo
oe oo
1. String ๐ state ee
2. String โaโ state oe
3. String โbโ state eo
4. String โaaโ state ee
5. String โabโ state oo
6. String โbaโ state oo
7. String โbbโ state ee
8. String โabaโ or โbaaโ state eo
9. String โbabโ or โabbโ state oe
a
b
a
b
a
b
a
b
25
26. Cross Product Method
โข ๐๐ ๐ ๐๐๐ 2 = 0 & ๐๐ ๐ ๐๐๐ 2 = 0
๐ด, ๐ต ร ๐ถ, ๐ท = ๐ด๐ถ, ๐ด๐ท, ๐ต๐ถ, ๐ต๐ท
A B
a
a
b
b
C D
b
b
a
a
b
a
b
a
b
a
b
a
A B
C C
a
a
b
b
A A
C D
AC BC
AD BD
ee oe
oo
eo
Observation: โaโs are counting
in horizontal way and โbโs are
counting in vertical way. 26
27. Cross Product Method
โข Construct a DFA that accept all strings over the
alphabets {a, b} where number of โaโ is divisible by 3
and number of โbโ in the string is divisible by 2.
b
a
a
b
00 10
01 11
20
b
21
a
a
a
a
b
b
b
27
28. Cross Product Method
โข Construct a DFA that accept all strings over the alphabets {a,
b} where number of โaโ and number of โbโ in the string is
divisible by 3.
โ ๐๐ ๐ ๐๐๐ 3 = 0 & ๐๐ ๐ ๐๐๐ 3 = 0
โ ๐๐ ๐ โ 0 ๐๐๐ 3 & ๐๐ ๐ โ 0 ๐๐๐ 3
b
a
a
b
A B
D E
C
b
F
a
a
a
a
b
a
b
G H
b
I
a
a
b
b
b
28
29. DFA
โข Construct a DFA that accept all strings over the alphabets {a,
b} such that ๐๐ ๐ ๐๐๐ 3 โฅ ๐๐ ๐ ๐๐๐ 2
b
a
a
b
00 10
01 11
20
b
21
a
a
a
a
b
b
b
No. of โaโs mod 3 >
no. of โbโs mod 2
this will be a final
state
No. of โaโs mod 3 >
no. of โbโs mod 2
this will be a final
state
No. of โaโs mod 3 =
no. of โbโs mod 2
this will be a final
state
No. of โaโs mod 3 >
no. of โbโs mod 2
this will be a final
state
No. of โaโs mod 3 =
no. of โbโs mod 2
So this will be a
final state
No. of โaโs mod 3 <
no. of โbโs mod 2
this will not be a
final state
29
30. DFA
โข Construct a minimal DFA which accepts all
strings over {0,1}, which when interpreted as
binary number is divisible by 2.
โ Two remainders are possible, so two states
๐๐ ๐๐
1
0
1
0
30
31. DFA
โข Construct a minimal DFA which accepts all
strings over {0,1}, which when interpreted as
binary number is divisible by 3.
โ Three remainders are possible, so three states
๐๐ ๐๐
1
1
0
0
๐๐
0
1
If the question is divisible by โnโ then number of state is n.
31
33. Transition Table
โข Construct a minimal DFA which accepts all
strings over {0,1}, which when interpreted as
binary number is divisible by 4
0 1
๐0 ๐0 ๐1
๐1 ๐2 ๐3
๐2 ๐0 ๐1
๐3 ๐2 ๐3
33
34. DFA
โข Construct a minimal DFA which accepts all
strings over {0,1}, which when interpreted as
binary number is โ 1 ๐๐๐ 3.
๐๐ ๐๐
1
1
0
0
๐๐
0
1
34
35. DFA
โข Construct a minimal DFA which accepts all
strings over {0,1}, which when interpreted as
binary number is โ 2 ๐๐๐ 3.
๐๐ ๐๐
1
1
0
0
๐๐
0
1
35
36. Transition Table
โข Construct a minimal DFA which accepts all
strings over {0,1,2}, which when interpreted as
ternary number is divisible by 4
0 1 2
๐0 ๐0 ๐1 ๐2
๐1 ๐3 ๐0 ๐1
๐2 ๐2 ๐3 ๐0
๐3 ๐1 ๐2 ๐3
36
37. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string starts
with an โaโ.
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string
contains an โaโ.
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string ends
with an โaโ.
37
38. Assignment
1. Construct a DFA that accept all strings over the alphabets {a, b} where number of
โaโ and number of โbโ is odd in the string.
2. Construct a DFA that accept all strings over the alphabets {a, b} where number of
โaโ is even and number of โbโ is odd in the string .
3. Construct a DFA that accept all strings over the alphabets {a, b} where number of
โaโ is odd and number of โbโ is even in the string .
4. Construct a DFA that accept all strings over the alphabets {a, b} where number of
โaโ is multiple of three and number of โbโ is multiple of two in the string.
5. Construct a DFA that accept all strings over the alphabets {a, b} such that
๐๐ ๐ ๐๐๐ 3 = ๐๐ ๐ ๐๐๐ 2
6. Construct a DFA that accept all strings over the alphabets {a, b} such that
๐๐ ๐ ๐๐๐ 3 โค ๐๐ ๐ ๐๐๐ 2
7. Construct a DFA that accept all strings over the alphabets {a, b} such that
๐๐ ๐ ๐๐๐ 3 = 1 and ๐๐ ๐ ๐๐๐ 3 = 2
8. Construct a DFA that accept all strings over the alphabets {a, b} such that
๐๐ ๐ ๐๐๐ 3 > ๐๐ ๐ ๐๐๐ 3
9. Construct a minimal DFA which accepts all strings over Octal number system,
which when interpreted as binary number โ 1 ๐๐๐ 5
38
39. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string start
with โabโ
โ L= {ab, aba, abb, โฆโฆโฆ}
B C
A
a b
D
a, b
a
a, b
39
b
40. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string
contains โabโ as a sub string.
โ L= {ab, aab, aba, bab, abb โฆโฆโฆ}
B C
A
a b
b a a,b
40
41. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} where each string end
with โabโ
โ L= {ab, aab, bab, abab โฆโฆโฆ}
B C
A
a b
b a
a
b
41
42. DFA
โข Construct a minimal DFA which accepts set of all
strings over {a, b} where each string starts with โaโ
and ends with โbโ or vice versa.
โ L ={ab, ba, aab, abb, baa, bba. โฆโฆ}
B C
A
a b
b
a b
a
D
a
E
b
b
42
a
43. DFA
โข Construct a minimal DFA which accepts set of all
strings over {a, b} where each string starts and ends
with same symbol.
โ L={๐, a, b, aa, bb, aba, bab,โฆโฆโฆโฆ}
C
B
A
a b
b
a
b
a
E
a
D b
b
a
This DFA is complement of
previous DFA and language also.
We will get complement of a
language by removing one
language from ๐บโ. ๐ณ๐ = ๐บโ โ ๐ณ๐
L2 is complement of L1
43
44. Complement of DFA
A B
a
Length
Even
Length
Odd
a
b
b
A B
a
Length
Even
Length
Odd
a
b
L1 = Even number of โaโ L2 = Odd number of โaโ
L3 = Starts with โaโ L4 = Not starts with โaโ
A B
C
a
b
a,b
a,b
A B
C
a
b
a,b
a,b
44
45. Complement of DFA
โข DFA can be defined by quintuples
โ ( ๐ , ฮฃ , ๐ฟ , ๐ 0 , ๐น )
โข Complement of DFA can be defined by
quintuples
โ ( ๐ , ฮฃ , ๐ฟ , ๐ 0 , ๐ โ ๐น )
45
46. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} which accepts strings in
which every 'a' is followed by 'b'.
โ L={๐, b, ab, bb, aba, bab, โฆโฆโฆโฆ}
46
C
B
A a b
a
b
a
b
D
a,b
47. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} which accepts strings in
which every 'a' never followed by 'b'.
โ This is not complement of previous
โ L={๐, a, aa,โฆ..,b, bb,โฆโฆ, ba, bbaโฆโฆโฆโฆ}
47
C
B
A
a b
a
a,b
b
48. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} which accepts strings in
which every 'a' is followed by โbb'.
48
D
B
A a b
a
b
a
b
E
a,b
C
b
a
49. DFA
โข Construct a minimal DFA which accepts set of
all strings over {a, b} which accepts strings in
which every 'a' never followed by โbb'.
49
D
B
A a b
a, b
a
b
C
b
a
50. DFA
โข ๐ฟ = ๐๐
๐๐
|๐, ๐ โฅ 1
โ ๐ฟ = {๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐, โฆ โฆ โฆ }
50
C
B
A a
b
b
a
D
a, b
b
a
51. DFA
โข ๐ฟ = ๐๐
๐๐
|๐, ๐ โฅ 0
โ ๐ฟ = {๐, ๐, ๐๐, โฆ , ๐๐๐, ๐๐๐, โฆ ๐, ๐๐, ๐๐๐ โฆ โฆ โฆ }
51
C
B
A
b a
b a,b
a
52. DFA
โข ๐ฟ = ๐๐
๐๐
๐๐
|๐, ๐, ๐ โฅ 1
โ ๐ฟ = {๐๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐, โฆ โฆ โฆ }
52
D
B
A a
b, c
c
c
D
a, b, c
b
a
C
c
a
b
a, b
53. DFA
โข ๐ฟ = ๐๐
๐๐
๐๐
|๐, ๐, ๐ โฅ 0
โ ๐ฟ = {๐, ๐, ๐, ๐, ๐๐, ๐๐, ๐๐, ๐๐๐, ๐๐, ๐๐, ๐๐, โฆ }
53
B
A b c
c
b
a
C
c
a
D
a, b, c
a, b
54. DFA
โข ๐ฟ = {๐3
๐๐ค๐3
|๐ค โ {๐, ๐}โ
}
โ ๐ฟ = {๐3๐๐๐3, ๐3๐๐๐3, ๐3๐๐๐3, ๐3๐๐๐๐3, โฆ โฆ }
54
H
B
A a a
C D E F G
a b a a a
I
b
a, b
b b a
b
b
b
b
a
55. Operations of DFA
Different operations that we can apply on DFAs
are -
1. Union
2. Concatenation
3. Cross Product
4. Complement
5. Reversal
55
56. Union
โข Union of two Regular language is also Regular
โ L1 = starts with โaโ and ends with โbโ
โ L2 = starts with โbโ and ends with โaโ
โ ๐ฟ = ๐ฟ1 โช ๐ฟ2 = starts with different symbol
โข Let,
๐ด๐ = ๐1, ฮฃ1, ๐ฟ1, ๐0
1, ๐น1 DFA for L1 , ๐ด๐ = ๐2, ฮฃ2, ๐ฟ2, ๐0
2, ๐น2 DFA for L2
We want to construct M for ๐ณ = ๐ฟ1 โช ๐ฟ2
๐ด = ๐, ฮฃ, ๐ฟ, ๐0, ๐น DFA for L
Where,
๐ธ = ๐1 ร ๐2
๐ฎ = ฮฃ1 โช ฮฃ2
๐น ๐1, ๐2 , ๐ = ๐ฟ1 ๐1, ๐ , ๐ฟ2 ๐2, ๐
๐๐= ๐0
1, ๐0
2
๐ญ = ๐1, ๐2 | ๐1 โ ๐น1 ๐๐ ๐2 โ ๐น2
56
๐1 โ ๐1 ๐๐๐ ๐2 โ ๐2
60. Reversal
โข L1= starts with โaโ
โ ๐ฟ1 = {a, aa, ab, aaa, aab, aba,โฆโฆ}
โ ๐ฟ1๐ = {a, aa, ba, aaa, baa, aba,โฆโฆ}
โข Steps:
โ States are same as original
โ Convert initial state to final state
โ Convert final state to initial state
60
A a
a, b
B
b
C
a, b
A
a
a, b
B
b
C
a, b
This is not DFA it is NFA
If we reverse a DFA of a
language we will get a
reverse language, but we
may or may not get
reverse DFA. Reverse FA is
either DFA or NFA.
Editor's Notes
โ congruent to
E = Even, O = Odd
Lecture 8: {0,1,2} ternary number where base is 3.
This rule is only for DFAโs not for NFAโs
Final state of 1st DFA is initial state of 2nd DFA
If we reverse a DFA of a language we will get a reverse language, but we may or may not get reverse DFA. Reverse FA is either DFA or NFA.