Docsity

DFA Construction: Building Finite Automata for Various Conditions - Prof. Santosh Pande, Study notes of Computer Science

Partial preview of the text

Download DFA Construction: Building Finite Automata for Various Conditions - Prof. Santosh Pande and more Study notes Computer Science in PDF only on Docsity!

DFA Construction Examples

DFA Construction

• 1. Strings of a’s and b’s such that thereare at least 3 consecutive a’s

S^

S^

S^

S

b

b b

b

a^

a^

a

a

DFA Construction

• Strings of a’s and b’s such that there 3 a’s^ do not

appear consecutivelyS^

S^

S^

S

b

b b

b

a^

a^

a

a

DFA Construction

-^ Intuition behind the construction– Every time you get a problem “strings such that

condition x

is^ not

satisfied”, create a DFA with a “core” which checks for

condition x

-^ In the previous example, S

→^ S

→^ S

→^ S4 is the “core”

  • If the condition is satisfied, “trap” it in an

rejecting

state

-^ In the previous example, once you have checked it for 3 consecutive a’s, youare “trapped” in the

rejecting

state S4. That is subsequent a’s and b’s will

cause you to remain in S4 and you cannot ever go to the accepting statefrom S4• Mark all the other states as accepting state

  • If during the check for the condition, the condition is violated start over•

In the previous example, assume we had a sub-sequence “aab”. Uponencountering the “b”, we start over by going back to state S

-^ Note– If you construct a DFA “D” for checking

“condition x”,

a new DFA such

that all accepting states of “D” are marked as normal states and allnormal states of “D” are marked as accepting states, then the new DFAchecks for the inverse of condition x. Compare the solution of problem 1with the solution for problem 2, and convince yourself that this is true

DFA Construction

-^ Intuition behind the construction– Every time you get a problem “strings such that

condition x

or

condition x

satisfied”, create a DFA with a “core” which checks

for^ condition x

-^ In the previous example, S

→^ S

→^ S3 is the “core”

  • If the condition is satisfied, “trap” it in an accepting state•

In the previous example, once you have checked it for twoconsecutive b’s, you are “trapped” in the accepting state S3. That is,subsequent a’s, b’s and c’s will cause you to remain in theaccepting state

  • If during the check for the condition, the condition is violated startover•

In the previous example, assume we had a sub-sequence “ba”.Upon encountering the “b”, we start over by going back to state S

  • Cont on next slide….

DFA Construction

– Similarly create a “core” for

condition y

– We now have to “compose” these two DFA’stogether• Merge the “start” states• Merge the “accept” states (if possible)• Take the DFA that checks for

condition x

and add

transitions to states of the DFA that checks for condition y

and vice-versa

  • S

→^ S4 and S

→^ S2 respectively

DFA Construction

• You now know how to– Check for condition x– Check for

not

condition x

– Check for condition x

or^

condition y

– Check for condition x

and

condition y

• Using this, you can construct a generalDFA