CS154
Chris Pollett
Feb. 9, 2011
At the end of Monday, we gave the following formal definition of deterministic finite automata (DFA):
public abstract class Automata
{
public Automata()
{
}
public void setState(int state)
{
currentState = state;
}
public boolean processString(String w)
{
for(int i = 0; i < w.length(); i++)
{
currentState = delta(currentState, w.charAt(i));
}
boolean accept = finalState(currentState);
return accept;
}
public abstract int delta(int state, char c);
public abstract boolean finalState(int state);
int currentState;
}
public class TestAutomata extends Automata
{
public TestAutomata()
{
}
public int delta(int state, char c)
{
int outState = 1;
switch(state)
{
case 1:
if(c == '0')
{
outState = 1;
}
else
{
outState = 2;
}
break;
case 2:
if(c == '0')
{
outState = 3;
}
else
{
outState = 2;
}
break;
case 3:
outState = 2;
break;
}
return outState;
}
public boolean finalState(int state)
{
return (state == 2) ? true : false;
}
public static void main(String args[])
{
TestAutomata test = new TestAutomata();
test.setState(1);
if(args.length == 0 ){
System.out.println("It is not recognized by this automata.");
}
System.out.println("Checking the string "+ args[0]);
if(test.processString(args[0]))
{
System.out.println("It is recognized by this automata.");
}
else
{
System.out.println("It is not recognized by this automata.");
}
}
}
Let `M= (Q, Sigma, delta, q0, F)` be a DFA, and GM be its associated transition graph. Then for every `q_i`, `q_j` in `Q` and `w` in `Sigma^star` , `delta^star(q_i,w) = q_j` iff there is in GM a walk with label `w` (that is, the edge labels written down as a string are `w`) from `q_i` to `q_j`.
Proof. We give a proof by induction on the length `n geq 0` of `w`. Notice `delta^star(q, epsilon)=q` corresponds exactly with a walk of length `0` in GM . So the `|w|=0` case holds. Assume the statement is true up to some `n`. Let `w=va` where `|v|=n`. (The induction step case.) Suppose `delta^star(q_i,v) = q_k` . By the induction hypothesis there is a walk `W` of length `n` in GM from `q_i`,to `q_k`. If `delta^star(q_i,w) = q_j` we must have `delta^star(q_i,w) = delta (delta^star(q_i,v), a) = q_j` by the definition of `delta^star.` So we have `delta(q_k,a) = q_j`. Thus, if we add to `W` the edge `(q_k, q_j)`, the label on the resulting walk will be `va=w` as desired. This new walk has length `n+1`. It is also not hard to turn this argument around to show if one stated with a walk of length `n+1` with label `w`, that one could show `delta^star(q_i,w) = q_j`. You should do this at home.