1 / 60

Deterministic Finite Automata (DFA)

Deterministic Finite Automata (DFA). DFA can be defined by quintuples is finite set of states is finite set of alphabets is transition function is initial state finite set of final states. Example of DFA. Transition Function. {A, B, C} X {a, b} {A, B, C} (A, a) (A, b ) (B, a )

marshap
Télécharger la présentation

Deterministic Finite Automata (DFA)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Deterministic Finite Automata (DFA) • DFA can be defined by quintuples • is finite set of states • is finite set of alphabets • is transition function • is initial state • finite set of final states

  2. Example of DFA

  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 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 C A

  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. a, b a, b a, b D a, b a a B B C C A A a, b B C A a, b

  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 languageby 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 a,b a,b B C A

  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 D a, b a,b a,b B C A

  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, b D E a, b a, b C a, b B A 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 Length Odd Length 0 Length 1 Length 2 Length Even a, b a, b a, b a, b B B C A A

  13. DFA • Construct a DFA that accept all strings over the alphabets {a, b} where the string length is notdivisible 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 B A 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. Length 0,3,6,… Length 1,4,7,… Length 2,5,8,… a, b C a, b B A a, b

  15. DFA • Construct a DFA where • means • For (m is any number) in general for minimal DFA we need number of states. Length 0,3,6,… Length 1,4,7,… Length 2,5,8,… a, b C a, b B a, b A

  16. DFA • Construct a DFA that accept all strings over the alphabets {a, b} where number of ‘a’ in the string is two. b b b a,b D A a a a B C 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. b a, b b A a a B C 0 ‘a’s 1 ‘a’s 2 ‘a’s

  18. DFA • Construct a DFA that accept all strings over the alphabets {a, b} where number of ‘a’ in the string at most two. b b b a,b a a C a B A D 0 ‘a’s 1 ‘a’s 3 ‘a’s 2 ‘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. b b B A a Length Odd a 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. b b B A a Length Odd a 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 b b b C B A a a a

  22. DFA • , how to draw DFA?? • number of states will be there • If k=0 will be final state • If k=1 will be final state • If k=2 will be final state • If k=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 • Construct a DFA that accept all strings over the alphabets {a, b} such that

  24. DFA • Construct a DFA that accept all strings over the alphabets {a, b} where number of ‘a’ and number of ‘b’ in the stringis even. • & • & Four possible states representing this situation

  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 b ee eo b b a a a a b oe oo

  26. Cross Product Method • & = a AC BC a a b a b b b b a b ee oe D B A C a a b b a b a A A C D A B C C AD BD b a Observation: ‘a’s are counting in horizontal way and ‘b’s are counting in vertical way. eo oo

  27. Cross Product Method • Construct a DFA that accept all strings over the alphabets {a, b} where number of ‘a’ is divisible by 3and number of ‘b’ in the string is divisible by 2. a 00 10 a 20 a b b a a b b b b 21 01 11 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 & 3 a A B a C a b b b b b b F D E b b b a a a a a I G H a

  29. DFA • Construct a DFA that accept all strings over the alphabets {a, b} such that 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 a No. of ‘a’s mod 3 > no. of ‘b’s mod 2 this will be a final state a 00 10 a 20 b b b 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 No. of ‘a’s mod 3 > no. of ‘b’s mod 2 this will be a final state a a b b b 21 01 11 a

  30. DFA • Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted asbinary number is divisible by 2. • Two remainders are possible, so two states 0 1 1 0

  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 0 1 1 0 1 0 If the question is divisible by ‘n’ then number of state is n.

  32. Transition Table 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

  34. DFA • Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted as binary number is . 0 1 1 0 0 1

  35. DFA • Construct a minimal DFA which accepts all strings over {0,1}, which when interpreted as binary number is . 1 0 1 0 1 0

  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

  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 • Construct a DFA that accept all strings over the alphabets {a, b} such that • Construct a DFA that accept all strings over the alphabets {a, b} such that • Construct a DFA that accept all strings over the alphabets {a, b} such that • Construct a minimal DFA which accepts all strings over Octal number system, which when interpreted as binary number

  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 b B C A 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 b B C A

  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 b B C A 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 b B C A 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 C b B 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 L1 = Even number of ‘a’ L2 = Odd number of ‘a’ a,b L3 = Starts with ‘a’ L4 = Not starts with ‘a’ b b A B a a,b b B A a A B a B A a b b Length Odd a Length Even C C Length Odd a a,b Length Even a,b

  45. Complement of DFA • DFA can be defined by quintuples • Complement of DFA can be defined by quintuples

  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 C b B 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…………} a,b b a a A C 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'. a b b A a b D b C B 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 D b C B a

  50. DFA b a A a b C B a b D a, b

More Related