Deterministic Finite Automata
Alphabet and strings
Alphabet
Link copiedLet be a finite alphabet. When contains letters, we say is a -letter alphabet. A 1-letter alphabet is a unary alphabet, and a 2-letter alphabet is a binary alphabet. Our typical binary alphabet is . A finite sequence of symbols from is called a string or word.
Strings
Link copiedEach string is of the form where . The length of , denoted by , is the number of symbols it has. Thus, , , and .
The string of length is called the empty string. It is denoted .
There are strings of length over a -letter alphabet.
Concatenation operation
Link copiedThe set of all strings over the alphabet is
We denote strings by the letters .
The concatenation of and is obtained by writing followed by . Concatenation is denoted by . We have:
Note that for any string , because is the empty string, we have .
We sometime write , instead of .
Substrings
Link copiedFor a string we denote by the following string:
If a string occurs in a string , we say that is a substring of . That is, is a substring of if for some strings and . One can see that every string is a substring of itself (take ).
A string is a prefix of a string if can be written as .
For example, The prefixes of are , , , , , and .
Languages
Link copiedA language over an alphabet is a subset of .
Here are some examples of languages:
- , , , .
- is a substring of .
- has even length .
- has a substring .
We denote languages by , , , , .
Operations on languages
Boolean operations
Link copiedLet and be languages over an alphabet . The following operations on languages are called Boolean operations:
- The union of and is ,
- The intersection of and is ,
- The complement of is .
Concatenation operation
Link copiedLet and be languages on some alphabet set . The concatenation of and , denoted by , is the language .
Deterministic finite automata
Let be a language over an alphabet . Suppose we are given a string , and we would like to check whether belongs to . A deterministic finite automaton (DFA) is an algorithm that determines whether belongs to or not.
We can represent a finite automata as a labeled directed graph. We call this graph the transition diagram.
Formal definition of a DFA
Link copiedDefinition 7.1 _A deterministic finite automaton (DFA) is a -tuple , where
- is the set of states.
- is the transition function .
- is a subset of called the set of accepting states.
- is an alphabet.
- is the initial state. Note that .
Example 7.2 Let us look at the language that consists of all strings such that contains the substring . We want to design an algorithm that, given a string , determines whether . Below is the - -algorithm that on input
determines if contains as a sub-string (and if it does, then ).
Find-baa(v)-algorithm
The algorithm makes its transitions from one state to another depending on the input symbol read. The transition function is given by the following Table.
We can represent a finite automata as a labeled directed graph. We call this graph transition diagram. Therefore we have the following transition diagram for the - -algorithm.
As a program, the algorithm Find-baa is the following:
- Initialize variables and .
- If and then set .
- If and then set .
- If and then set .
- If and then set .
- If and then set .
- If and then set .
- If and then .
- Increment by one.
- If then go to Line 11. Otherwise go to Line .
- If then output accept. Otherwise output reject.
Runs and acceptance
Link copiedLet be a DFA and be a string. The run of the automaton on is the sequence of states such that is the initial state and for all .
The run of on a string can be viewed of as the execution the following algorithm :
- Initialize , , and print .
- While do
(a) Set .
(b) Set .
(c) Print .
(d) Increment
Let be a DFA and be a string. We say that accepts if the run of on is such that the last state . Such a run is called an accepting run.
DFA recognizable languages
Link copiedLet be a DFA. The language accepted by , denoted by , is the language the automaton accepts .
A language is DFA recognizable if there exists a DFA such that .
Example 7.4 Consider a DFA with exactly one state. If the state is an accepting state, then the automaton accepts the language . If the state is not an accepting state, then the automaton recognizes the empty language .
This language is recognized by the following DFA :
-
with being the initial state.
-
For all , . In other cases .
-
The accepting state is .
Designing finite automata
Given a language , we would like design a deterministic finite automata that recognizes the language . But can we always do so? And if so, how?
For example, let us consider the language . Is there a DFA recognising ?
Our problem is to design a DFA recognizing this language.
One way of doing so, is to count the number of ‘s and ‘s in each given word. But we don’t really need to count the number of ‘s and ‘s. We just need to keep track of four cases: whether the number of ‘s is odd or even, and whether the number of ‘s is odd or even. We can do this with four states:
State 0: Even number of ‘s and ‘s.
Stete 1: Even number of ‘s and odd number of ‘s .
State 2: Odd number of ‘s and ‘s.
State 3: Odd number of ‘s and even number of ‘s.
We get the following transition diagram:
Designing finite automata
Union automata
Link copiedLet and , and let two DFA recognizing and .
The Union Problem: Design a DFA that recognizes .
Construction of DFA for
-
The set of states is .
-
The initial state is the pair .
-
The transition function is the product of the transition functions and , that is:
where , , and .
- The set of final states consists of all pairs such that either or .
The notation for the new automaton is: .
Why does the construction work?If then either accepts or accepts . In either case, since simulates both and , the string must be accepted by .
If is accepted by then the run of on is split into two runs: one is the run of on and the other is the run of on . Since accepts , it must be the case that one of the runs is accepting.
Intersection automata
Link copiedLet and , and let two DFA recognizing and .
The intersection problem : Design a DFA that recognizes .
Construction of DFA for
-
The set of states is .
-
The initial state is the pair .
-
The transition function is the product of the transition functions and , that is:
where , , and .
- The set of final states consists of all pairs such that and .
The notation for the automaton is this: .
Complementation automata
Link copiedThe complementation problem :
Given a DFA , design a DFA that recognizes the complement of .
This is a simple procedure. Keep the original states, the initial state, and the transition function . Swap: Declare non-accepting states as accepting, and accepting states non-accepting.