Regular Languages
Learn about regular languages and explore some more examples of deterministic finite automata.
Formal definition
A regular language is a formal language for which there exists a deterministic finite automaton that accepts all and only those strings in the language.
Let’s look at a few examples of regular languages and their corresponding DFA.
DFA accepting strings starting with and ending with
Consider the language , of all strings that begin with an and end with a . We can write this language as . If the first symbol is a , then there is no hope of the machine accepting it. The following figure shows a machine that accepts all the strings starting with an and ending with a .
DFA accepting strings with a 1 in the next-to-last position
Consider the alphabet . How would we construct a DFA that accepts the language , which contains strings of zeros and ones where the next-to-last symbol is a ? Such a string must end with either or . This language can be written as .
Since we never know when the next-to-last input occurs, we need to track those two substrings whenever they occur. The following figure shows a DFA for the language .
The state labels reflect the substring just processed that led to each state. Observe how the out-edges from the accepting states behave. The last symbol read before reaching those states becomes the next-to-last symbol on the subsequent move.
DFA accepting strings with a 1 in the third-to-last position
Now let’s consider how to recognize strings over that end with a in the third-to-last position. Reading a starts us on a potential path to acceptance. From there, we’ll read a or , at which point we’ll have read one of or . An acceptable string must be of at least length three and end with , , , or . Thus, the language of our interest, is .
The possibilities that the input ends with ...