Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deterministic Finite Automata (DFA)

Similar presentations


Presentation on theme: "Deterministic Finite Automata (DFA)"โ€” Presentation transcript:

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


Download ppt "Deterministic Finite Automata (DFA)"

Similar presentations


Ads by Google