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.

State diagram of a vending machine

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: {0,1,2,,5,>5} \{0,1,2, \ldots, 5, >5\}
  • Well defined input: {1,2} \{1,2\}^*
  • Predetermined transition logic
  • Start state: {0} \{0\}
  • Actionable states: {5,>5} \{5, >5\}
  • 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 5 5 -tuple (Q,Σ,δ,q0,F) (Q, \Sigma, \delta, q_0, F) where

  • Q Q is a finite set called states,
  • Σ \Sigma is a finite set called alphabet,
  • δ:Q×ΣQ \delta: Q\times \Sigma \rightarrow Q is the transition function,
  • q0 q_0 is the start state, and
  • FQ F\subseteq Q is the set of accept states.

Afore mentioned rudimentary vending machine can be formalized as follows.

  • Q={q1,q2,q3,q4,q5,q>} Q = \{q_1, q_2, q_3, q_4, q_5, q_{>}\}
  • Σ={1,2} \Sigma = \{1,2\}
  • δ \delta is given by
1 2
q0 q_0 q1 q_1 q2 q_2
q1 q_1 q2 q_2 q3 q_3
q2 q_2 q3 q_3 q4 q_4
q3 q_3 q4 q_4 q5 q_5
q4 q_4 q5 q_5 q> q_{>}
q5 q_5 q> q_{>} q> q_{>}
q> q_{>} q> q_{>} q> q_{>}
  • q0 q_0 is the start state
  • F={q5} F = \{q_5\}

Finite State Automata representing the vending machine

Run of a Finite State Automaton

Given any string in Σ \Sigma^* , 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 q0 q_0 , and the accept state is q3 q_3 .

Automaton before it reads the given string

Automaton reads 1 and stays in q0 q_0 .

Automaton reads 1 and stays in q_0

Automaton reads 0 and moves to q1 q_1

Automaton reads 0 and moves to q_1

Automaton reads 1 and moves to q0 q_0

Automaton reads 1 and moves to q_0

Automaton reads 0 and moves to q1 q_1

Automaton reads 0 and moves to q_1

Automaton reads 0 and moves to q2 q_2

Automaton reads 0 and moves to q_2

Automaton reads 0 and stays in q2 q_2

Automaton reads 0 and stays in q_2

Automaton reads 1 and moves to q3 q_3

Automaton reads 1 and moves to q_3

Automaton accepts the string upon reaching q3 q_3 .

Language acceptance of a finite state automaton

A language is a set of strings over a given alphabet Σ\Sigma.

Given a machine M=(Q,Σ,δ,q0,F) M = (Q, \Sigma, \delta, q_0, F) ,

  • A string x x is accepted by machine MM if a run of machine MM on xx ends in an accepting state.
  • Language of M M , L(M)={wΣw isacceptedby M} L(M) = \{w\in\Sigma^{*}\mid w~\mathrm{is accepted by}~M \} .
  • For a set A A if L(M)=A L(M) = A , then M M recognizes AA.

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:

  1. Given a finite state automaton M M , can it happen that it accepts no strings?
  2. Given a set of strings over an alphabet Σ \Sigma , is there a DFA that accepts it?

Example 2

Automaton that recognizes strings that contain 001

The above automaton recognizes strings that contain 001.

  1. Language acceptance by Non-Deterministic Finite Automata
  2. Converting a NFA to a DFA
  3. Converting a Regular Expression to NFA