Lec 06-Finite Automata
Lec 06-Finite Automata
2
Example
• Let us build a machine that accepts the language of all words over the
alphabet Σ = {a, b} with an even number of letters.
• Use a Boolean flag, named E, initialized with the value TRUE. Every time
we read a letter, we reverse the value of E until we have exhausted the
input string. We then check the value of E. If it is TRUE, then the input
string is in the language; if FALSE, it is not.
3
Example Contd.
4
Example
• This is the language of all strings that begin with the letter a.
5
Example
6
Example
7
Example Contd.
• For similar reason, there must be a path for bbb, that has no
loop, and uses entirely differently states. If the b-path shares
any states with the a-path, we could mix a’s and b’s to get to
the final state. However, the final state can be shared.
8
Example Contd.
9
Example
10
Example
• There are only two ways to get to the final state 4 in this FA: One is from
state 2 and the other is from state 3.
• Thus, the words accepted by this machine are exactly those strings that
have a double letter aa or bb in them. This language is defined by the
regular expression
12
Example
• Notice that in states 2, 3, and 4, all a’s that are read are
ignored; and only b’s cause a change of state.
13
• Summarizing what we know: If an input string starts with an a
followed by some b’s, then it must have 3 b’s to return to the
final state 3, or 6 b’s to make the trip twice, or 9 b’s, or 12 b’s
and so on.
14
Example Contd.
• Such an input string will lead us to state 2. It then needs two more b’s to
get to the final state 3. These b’s can be separated by any number of a’s.
Once in state 3, it needs no more b’s, or 3 more b’s, or 6 more b’s and so
on.
15
Example EVEN-EVEN revisited
16
Example EVEN-EVEN revisited Contd.
• There are 4 edges labeled a. All the a-edges go either from one of the
upper two states (states 1 and 2) to one of the lower two states (states 3
and 4), or else form one of the lower two states to one of the upper two
states.
• If a string gets accepted by this FA, we can say that the string must have
had an even number of a’s in it. Every a that took us south was balanced
by some a that took us back north.
• So, every word in the language of this FA has an even number of a’s in it.
Also, we can say that every input string with an even number of a will
finish its path in the north (ie., state 1 or state 2).
17
Example EVEN-EVEN revisited Contd.
• Notice that all input strings that end in state 2 have an even
number of a’s but an odd number of b’s. All strings that end in
state 3 have an even number of b’s but an odd number of a’s.
All strings that end in state 4 have an odd number of a’s and
an odd number of b’s. Thus, every word in the language EVEN
- EVEN must end in state 1 and therefore be accepted.
18