More Deterministic Finite Automata




CS154

Chris Pollett

Feb. 6, 2013

Outline

Formal Definition

At the end of Monday, we gave the following formal definition of deterministic finite automata (DFA):

Example of the Definition

Homework Problems (Sec 1)

Problem 1. Prove by induction that, `sum_(i=0)^n (3i^(2) +3i +1) = (n+1)^3`. Show carefully that this sum is `Theta(n^3)`.

Answer. As an aside whenever you see a sum like the above you should be suspicious that it comes from a telescoping series -- the technique of the ancients like Archimedes to do integration before the development of differentiation. A telescoping series is one of the form: `sum_{i=0}^{n}(a_(i+1) - a_i) = a_(n+1) - a_0`. The equality is because all except the first and last term in this series cancel. In particular, `sum_(i=0)^n ((i+1)^3 - i^3) = (n+1)^3`, but if we expand each summand we get `(3i^(2) +3i +1)`. To see that the original statement is true by induction, we need to show that it holds when `n=0` and that whenever it hold for some natural number `n > 0` it also holds of `n+1`. First consider the case when `n=0`. Then the sum above is:
`sum_(i=0)^0 (3i^(2) +3i +1) = 3 cdot 0^2 + 3cdot 0 + 1 = 1 = (0 + 1) ^3.`
Hence, the `n=0` case holds. Suppose the statement is true up to some `n > 0`. Consider the sum up to `n+1`:
`sum_(i=0)^(n+1) (3i^(2) +3i +1) = (3(n+1)^(2) +3(n+1) +1) + sum_(i=0)^n (3i^(2) +3i +1)`
Using the induction hypothesis we have:
`sum_(i=0)^(n+1) (3i^(2) +3i +1) = (3(n+1)^(2) +3(n+1) +1) + (n+1)^3`
`quad = (n+1)^3 + 3(n+1)^(2) +3(n+1) +1 = ((n+1) + 1)^3 = (n+2)^3.`
Hence, the induction hypothesis holds and the statement is proven.

Given `sum_(i=0)^n (3i^(2) +3i +1) = (n+1)^3`, we next want to show the sum on the LHS is `Theta(n^3)`. According to the definition, this means we need to show `(n+1)^3 = O(n^3)` and `n^3 = O((n+1)^3)`. To show the first statement, notice when `n geq 1` we have `n+1 leq n + n = 2n` and so `(n+1)^3 leq (2n)^3 = 8n^3`. So for all `m geq N = 1`, if `c=8`, `(m+1)^3 leq c m^3`. Therefore, `(n+1)^3 = O(n^3)`. To see the second statement notice `n leq n+1` and so since cubing is a nondecreasing function, `n^3 leq (n+1)^3`. So for all `m geq N = 1`, if `c=1`, `m^3 leq c (m+1)^3`. Therefore, `n^3 = O((n+1)^3)`.

Problem 3. Draw a finite automata that accepts all string over `{0,1}` that have an even number of `1`'s.

Answer. In designing a finite automata, the first question we should ask is whether the start state is accepting or not. In this case, the empty string has zero 1's in it and zero is and even number, so the empty string should be accepted, and hence, the start state should be accepting. Next we should ask for each alphabet symbol `a`, if I had started with that alphabet symbol `a`, is there a string `v` such that my behavior on `epsilon v` should be different from `a v`. For the question at hand the machines behavior on `epsilon v` and `0 v` should be the same however for `epsilon v` and `1 v` the behavior should not always be the same. For example, if `v = epsilon`, then `epsilon v = epsilon ` is in the language, but `1 v = 1` is not. From this, we get that on a `0` we should remain in the same state, but on a `1` we should go to a different state. Continuing in this fashion, we could come up with the following machine:

Two state DFA for this problem

Homework Problems (Sec 3)

Problem 2. Using the pigeonhole principle, show that every undirected graph without loops with two or more nodes contains two nodes that have equal degree.

Answer. The (injective) pigeonhole principle says that for every map `f: A->B` where `|A| > |B|`, there exists `x ne y in A` such that `f(x) = f(y)`. At home you should try to prove this statement by induction. Suppose we have an undirected graph `G = (V, E)` where `|V| geq 2` which has no loops. Recall for `v in V` the degree of `v`, `deg(v)`, is the number of edges leaving `v`. Since we are assuming there are no loops, each edge must be connected to some other vertex (we use vertex and node interchangeably). So the `deg(v) < |V|`. We can define a function `f:V-> {0,..., |V| - 1}` by `f(v) mapsto deg(v)`. Consider the case where there is a `v` such that `deg(v)=0`. If some other vertex `v'` also has `deg(v') = 0` we are done. Suppose not, then `f` restricted to `V - {v}` is a map from `V-{v} -> {1,... , |V| - 2}`. Since `|V-{v}| = |V| - 1`, by the pigeonhole principle we can find `v' ne v'' in V -{v}` such that `deg(v')=f(v')=f(v'')=deg(v'')`. Now suppose there is no `v in V` with `deg(v) = 0`. Then `f:V-> {1, ...,|V| - 1}`. I.e., it is a map of a set of size `|V|` into one of size `|V| -1`, so by the pigeonhole principle we can find `v' ne v'' in V -{v}` such that `deg(v')=f(v')=f(v'')=deg(v'')`. QED.

Problem 4. Write down the automata of the previous problem formally as a 5-tuple.

Answer. The following is a possible state diagram that solves Problem 3:

Two state DFA for this problem

We can write this machine a 5-tuple: `(Q, Sigma, delta, q_0, F)` if we set:

Implementing Finite Automata -- Base Class

Implementing Finite Automata -- Specific Automata

Comments on Code

Formal Definition of Accepting a String

The Extended Transition Function

Designing Automata

Trap States

Walks on Automata

Theorem

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.

Regular Operations