Designing DFAs
So far we have discussed how to determine the language of a DFA:
We want to also perform the reverse, given a language , design a DFA such that the language of is .
Example Task 1
Design a DFA such that consists of all the strings of s and s ending with .
- Determine what to remember about the input string, while the head is reading through it, from left to right.
- Add the transitions telling how the possibilities rearrange, and select the initial state and the favourable states.
- Test the automaton.
It is sufficient to remember three ‘states’ of the string read so far:
- The string does not end in . (it is either or ends in ) initial state (waiting for )
- String is or ends in . (waiting for )
- String ends in . favourable state
digraph {
rankdir=LR
init[shape=point]
node[shape=doublecircle]; p;
node[shape=circle];
init->s
s->s [label=0]
s->q [label=1]
q->s [label=0]
q->p [label=1]
p->s [label=0]
p->p [label=1]
}Example Task 2
Design a DFA such that consists of all the strings of and whose length is divisible by . Consider that:
digraph {
rankdir=LR
init[shape=point]
node[shape=doublecircle]; s;
node[shape=circle];
init->s
s->s [label="0,3,6,9"]
p->p [label="0,3,6,9"]
q->q [label="0,3,6,9"]
s->p [label="1,4,7"]
p->q [label="1,4,7"]
q->s [label="1,4,7"]
p->s [label="2,5,8"]
p->q [label="2,5,8"]
q->s [label="2,5,8"]
}Pattern Matching
Design a DFA such that consists of all the strings of s and s that contain as a substring.
digraph {
rankdir=LR
init[shape=point]
node[shape=doublecircle]; aab;
node[shape=circle];
init->s
s->s [label=b]
s->a [label=a]
a->s [label=b]
a->aa [label=a]
aa->aa [label=a]
aa->aab [label=b]
aab->aab [label=a]
aab->aab [label=b]
}