Download presentation
Presentation is loading. Please wait.
1
Deterministic Finite Automata (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
2
Example of DFA ๐= ๐ด, ๐ต, ๐ถ ฮฃ= ๐,๐ ๐ฟ:๐ ฮง ฮฃโ๐ ๐ 0 =๐ด ๐น={๐ต}
3
Transition Function A B C A B C ๐ฟ:๐ ฮง ฮฃโ๐
{A, B, C} X {a, b} ๏ {A, B, C} (A, a) (A, b) (B, a) (B, b) (C, a) (C, b) A B C A B C For every input on a state there is exactly one transition.
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.
5
DFA Construct a DFA, that accepts set of all strings over {a, b} of length 2. Ans: ฮฃ= ๐,๐ ๐ฟ={๐๐, ๐๐, ๐๐, ๐๐} A a B a C
6
DFA B B B D C A C A C A Is this a complete DFA? No
Now is this a complete DFA? 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, b a, b a, b B C A a, b a, b D
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.
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 C a,b A B a,b
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. D a, b C a,b A B a,b
10
Minimum number of states
๐ =๐ ๐ โฅ๐ ๐ โค๐ ๐ =๐ n + 2 ๐ โฅ๐ n + 1 ๐ โค๐ n + 2
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 a, b B a, b C a, b D a, b E Length 0 Length 1 Length 2 Length 3 Length 4
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 Length 0 Length 1 Length 2 a, b A B a, b Length Even Length Odd
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 a, b B Length Even Length Odd a, b
14
DFA Construct a DFA that accept all strings over the alphabets {a, b} where the string length is divisible by three. ๐ ๐๐๐ 3=0 ๐ฟ={๐, ๐๐๐,โฆโฆโฆ,๐๐๐,๐๐๐๐๐๐,โฆโฆโฆ,๐๐๐๐๐๐,โฆโฆโฆโฆโฆโฆ} Length 0,3,6,โฆ Length 1,4,7,โฆ Length 2,5,8,โฆ A a, b B a, b C a, b
15
DFA B Construct a DFA where ๐ โ
1 ๐๐๐ 3 A C ๐ โ
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 Length 0,3,6,โฆ Length 1,4,7,โฆ Length 2,5,8,โฆ B โ
congruent to
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 b b C a a,b A B a a D 0 โaโs 1 โaโs 2 โaโs 3 โaโs
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 0 โaโs 1 โaโs 2 โaโs A b a, b
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 0 โaโs 1 โaโs 2 โaโs A a,b a D 3 โaโs
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 b b A B a a Length Odd Length Even
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 b A B a a Length Odd Length Even
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 b C
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
23
Assignment Construct a DFA that accept all strings over the alphabets {a, b} where number of โbโ in the string is divisible by 5. Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ โ
2 ๐๐๐ 5 Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ โ
1 ๐๐๐ 3
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 = Even, O = Odd Four possible states representing this situation E O
25
DFA 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 ee eo oe oo b b a a a a b b
26
Cross Product Method B D A C ๐ ๐ ๐ ๐๐๐ 2=0 & ๐ ๐ ๐ ๐๐๐ 2=0
๐ ๐ ๐ ๐๐๐ 2=0 & ๐ ๐ ๐ ๐๐๐ 2=0 ๐ด,๐ต ร ๐ถ,๐ท = ๐ด๐ถ,๐ด๐ท,๐ต๐ถ,๐ต๐ท A B a b C D b a ee AC BC AD BD oe a a b A B C C A A C D a b b b b Observation: โaโs are counting in horizontal way and โbโs are counting in vertical way. a eo oo a
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. a 00 a 10 a 20 b b b b b b 01 a 11 a 21 a
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 D E C F G H I
29
DFA Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ ๐๐๐ 3โฅ ๐ ๐ ๐ ๐๐๐ 2 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 be a final state No. of โaโs mod 3 > no. of โbโs mod 2 this will be a final state a 00 a 10 a 20 No. of โaโs mod 3 < no. of โbโs mod 2 this will not be a final state No. of โaโs mod 3 = no. of โbโs mod 2 this will be a final state b No. of โaโs mod 3 > no. of โbโs mod 2 this will be a final state b b b b b 01 a 11 a 21 a
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 ๐ ๐ ๐ ๐ 1
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 ๐ ๐ ๐ ๐ 1 If the question is divisible by โnโ then number of state is n.
32
Transition Table 1 ๐ 0 ๐ 1 ๐ 2 q0 q1 q2 q0 q1 q2
33
Transition Table Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted as binary number is divisible by 4 1 ๐ 0 ๐ 1 ๐ 2 ๐ 3
34
DFA Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted as binary number is โ
1 ๐๐๐ 3. ๐ ๐ ๐ ๐ 1
35
DFA Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted as binary number is โ
2 ๐๐๐ 3. ๐ ๐ ๐ ๐ 1
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 1 2 ๐ 0 ๐ 1 ๐ 2 ๐ 3 Lecture 8: {0,1,2} ternary number where base is 3.
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โ.
38
Assignment 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. 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 . 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 . 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. Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ ๐๐๐ 3= ๐ ๐ ๐ ๐๐๐ 2 Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ ๐๐๐ 3 โค ๐ ๐ ๐ ๐๐๐ 2 Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ ๐๐๐ 3=1 and ๐ ๐ ๐ ๐๐๐ 3=2 Construct a DFA that accept all strings over the alphabets {a, b} such that ๐ ๐ ๐ ๐๐๐ 3> ๐ ๐ ๐ ๐๐๐ 3 Construct a minimal DFA which accepts all strings over Octal number system, which when interpreted as binary number โ
1 ๐๐๐ 5
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, โฆโฆโฆ} a, b A a B b C b a D a, 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 โฆโฆโฆ} a,b b a A a B b C
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 โฆโฆโฆ} a b a A a B b C b
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 a A a B b C b a D b a b a E
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,โฆโฆโฆโฆ} b a A a B b C b a D b 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 b a E a
44
Complement of DFA B B A A A B C A B C L1 = Even number of โaโ
L2 = Odd number of โaโ A B a Length Even Length Odd b A B a Length Even Length Odd b L3 = Starts with โaโ L4 = Not starts with โaโ This rule is only for DFAโs not for NFAโs A B C a b a,b A B C a b a,b
45
Complement of DFA DFA can be defined by quintuples
(๐, ฮฃ,๐ฟ, ๐ 0, ๐น) Complement of DFA can be defined by quintuples (๐, ฮฃ,๐ฟ, ๐ 0, ๐โ๐น)
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, โฆโฆโฆโฆ} b b A a B b C a a a,b D
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โฆโฆโฆโฆ} b a,b a A a B b C
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'. a b b A a B b C b D a a a,b E
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'. a a, b b A a B b C b D a
50
DFA C ๐ฟ= ๐ ๐ ๐ ๐ |๐,๐โฅ1 A B D ๐ฟ={๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐,โฆโฆโฆ} b a a b a b
๐ฟ= ๐ ๐ ๐ ๐ |๐,๐โฅ1 ๐ฟ={๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐,โฆโฆโฆ} b a A a B b C b a D a, b
51
DFA C ๐ฟ= ๐ ๐ ๐ ๐ |๐,๐โฅ0 A B ๐ฟ={๐,๐, ๐๐, โฆ,๐๐๐, ๐๐๐,โฆ๐, ๐๐, ๐๐๐โฆโฆโฆ} a b
๐ฟ= ๐ ๐ ๐ ๐ |๐,๐โฅ0 ๐ฟ={๐,๐, ๐๐, โฆ,๐๐๐, ๐๐๐,โฆ๐, ๐๐, ๐๐๐โฆโฆโฆ} a b a,b A b B a C
52
DFA D ๐ฟ= ๐ ๐ ๐ ๐ ๐ ๐ |๐,๐,๐โฅ1 A B C D ๐ฟ={๐๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐,โฆโฆโฆ} c
๐ฟ= ๐ ๐ ๐ ๐ ๐ ๐ |๐,๐,๐โฅ1 ๐ฟ={๐๐๐, ๐๐๐๐, ๐๐๐๐, ๐๐๐๐,โฆโฆโฆ} c a b A a B b C c D b, c c a a, b D a, b, c
53
DFA ๐ฟ= ๐ ๐ ๐ ๐ ๐ ๐ |๐,๐,๐โฅ0 A B C D
๐ฟ= ๐ ๐ ๐ ๐ ๐ ๐ |๐,๐,๐โฅ0 ๐ฟ={๐,๐, ๐, ๐, ๐๐, ๐๐, ๐๐, ๐๐๐, ๐๐, ๐๐, ๐๐,โฆ} b c a A b B c C c a, b a D a, b, c
54
DFA H ๐ฟ={ ๐ 3 ๐๐ค ๐ 3 |๐คโ {๐,๐} โ } A B C D E F G I
๐ฟ={ ๐ 3 ๐๐ ๐ 3 , ๐ 3 ๐๐ ๐ 3 , ๐ 3 ๐๐ ๐ 3 , ๐ 3 ๐๐๐ ๐ 3 ,โฆโฆ} a b A B H a a C a D b E a F a G a b b b b a b I b a, b
55
Operations of DFA Different operations that we can apply on DFAs are -
Union Concatenation Cross Product Complement Reversal
56
Union Union of two Regular language is also Regular Let,
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 ๐ 1 โ ๐ 1 ๐๐๐ ๐ 2 โ ๐ 2
57
Union B A a b C D a, b B A b a C D a, b b B A a C
58
Concatenation ๐ฟ1= ๐,๐๐,๐๐,๐๐๐,๐๐๐, ๐๐๐,โฆโฆ
Concatenation of two Regular language is also Regular L1 = starts with โaโ L2 = ends with โbโ ๐ฟ=๐ฟ1โ๐ฟ2 = starts with โaโ and ends with โbโ ๐ฟ1= ๐,๐๐,๐๐,๐๐๐,๐๐๐, ๐๐๐,โฆโฆ ๐ฟ2={๐,๐๐, ๐๐, ๐๐๐, ๐๐๐, ๐๐๐,โฆโฆ} ๐ฟ={๐๐, ๐๐๐, ๐๐๐, ๐๐๐๐,โฆโฆโฆ} 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
59
Concatenation A B A B C A B C D a, b a a b b a b a, b
Final state of 1st DFA is initial state of 2nd DFA
60
Reversal A B C A B C 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 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. 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. A a a, b B b C a, b A a B b This is not DFA it is NFA C a, b
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.