Language acceptance by Deterministic Finite Automata (DFAs)
Introduction
Consider the following example of a very rudimentary vending machine which only takes in 1 and 2 rupee coins as inputs, and all items are identical are priced at 5 rupees each. The vending machine pushes all the coins out if the input coins add up to 6 rupees without first adding up to 5 rupees, or any coin that is input after reaching 5 rupees.
Observe that the machine can be in states 1, 2, 3, 4, 5, and >5 depending on what the sum of coins input so far is. For the machine, the sequence of coins input so far do not matter.
Abstracting out the machine
Note that the following properties held for the above machine.
- Finite number of states:
- Well defined input:
- Predetermined transition logic
- Start state:
- Actionable states:
- No memory of previous states
This is in fact an example of what we call a deterministic finite state machines or finite state automaton. In short, we refer to them as DFAs.
Formal definition
A Deterministic Finite State Machine/Automaton (DFA) is a -tuple where
- is a finite set called states,
- is a finite set called alphabet,
- is the transition function,
- is the start state, and
- is the set of accept states.
Afore mentioned rudimentary vending machine can be formalized as follows.
- is given by
1 | 2 | |
---|---|---|
- is the start state
Run of a Finite State Automaton
Given any string in , we can simulate the finite state automaton using the predetermined transition function by reading the string bit by bit. Note that the start state is , and the accept state is .
Automaton reads 1 and stays in .
Automaton reads 0 and moves to
Automaton reads 1 and moves to
Automaton reads 0 and moves to
Automaton reads 0 and moves to
Automaton reads 0 and stays in
Automaton reads 1 and moves to
Automaton accepts the string upon reaching .
Language acceptance of a finite state automaton
A language is a set of strings over a given alphabet .
Given a machine ,
- A string is accepted by machine if a run of machine on ends in an accepting state.
- Language of , .
- For a set if , then recognizes .
The above definition does not use the word deterministic, and as we shall see in the next experiment, this also holds for non-deterministic finite state automata.
Things to ponder on:
- Given a finite state automaton , can it happen that it accepts no strings?
- Given a set of strings over an alphabet , is there a DFA that accepts it?
Example 2
The above automaton recognizes strings that contain 001.