Copyright (C) 2015, H. Conrad Cunningham

Acknowledgements: These lecture notes are for use with Chapter 2 of the textbook: Peter Linz. Introduction to Formal Languages and Automata, Fifth Edition, Jones and Bartlett Learning, 2012. The terminology and notation used in these notes are similar to those used in the Linz textbook. This document uses several figures from the Linz textbook.

Advisory: The HTML version of this document requires use of a browser that supports the display of MathML. A good choice as of December 2015 seems to be a recent version of Firefox from Mozilla.

Introduction

In chapter 2, we approach automata and languages more precisely and formally than in chapter 1.

A finite automaton is an automaton that has no temporary storage (and, like all automata we consider in this course, a finite number of states and input alphabet).

2.1 Deterministic Finite Accepters

2.1.1 Accepters

Linz Definition (DFA): A deterministic finite accepter, or dfa, is defined by the tuple M=(Q,Σ,δ,q0,F)M = ( Q, \Sigma, \delta, q_{0}, F ) where

A dfa operates as described in the following pseudocode:

currentState := q0q_{0}

position input at left end of string
while more input exists
currentInput := next_input_symbol
advance input to right
currentState := δ\delta(currentState,currentInput)
if currentState F\in F then ACCEPT else REJECT

2.1.2 Transition Graphs

To visualize a dfa, we use a transition graph constructed as follows:

2.1.3 Linz Example 2.1

The graph pictured in Linz Figure 2.1 represents the dfa M=({q0,q1,q2},{0,1},δ,q0,{q1})M = (\{ q_{0}, q_{1}, q_{2} \},\{ 0, 1 \},\delta, q_{0}, \{q_{1}\}), where δ\delta is represented by

δ(q0,0)=q0\delta(q_{0},0) = q_{0}, δ(q0,1)=q1\delta(q_{0},1) = q_{1}
δ(q1,0)=q0\delta(q_{1},0) = q_{0}, δ(q1,1)=q2\delta(q_{1},1) = q_{2}
δ(q2,0)=q2\delta(q_{2},0) = q_{2}, δ(q2,1)=q1\delta(q_{2},1) = q_{1}

Note that q0q_{0} is the initial state and q1q_{1} is the only final state in this dfa.

Linz Fig. 2.1: DFA Transition Graph

Linz Fig. 2.1: DFA Transition Graph

The dfa in Linz Figure 2.1:

What about 0111? 1100?

2.1.4 Extended Transition Function for a DFA

Linz Definition: The extended transition function δ*:Q×Σ*Q\delta^{*} : Q \times \Sigma^{*} \rightarrow Q is defined recursively:

δ*(q,λ)=q\delta^{*}(q,\lambda) = q
δ*(q,wa)=δ(δ*(q,w),a)\delta^{*}(q,wa) = \delta(\delta^{*}(q,w),a)

The extended transition function gives the state of the automaton after reading a string.

2.1.5 Language Accepted by a DFA

Linz Definition 2.2 (Language Accepted by DFA): The language accepted by a dfa M=(Q,Σ,δ,q0,F)M = ( Q, \Sigma, \delta, q_{0}, F ) is L(M)={wΣ*:δ*(q0,w)F}L(M) = \{ w \in \Sigma^{*} : \delta^{*}(q_{0}, w) \in F \}.

That is, L(M)L(M) is the set of all strings on the input alphabet accepted by automaton M.

Note that above δ\delta and δ*\delta^{*} are total functions (i.e., defined for all strings).

2.1.6 Linz Example 2.2

The automaton in Linz Figure 2.2 accepts all strings consisting of arbitrary numbers of aa's followed by a single bb.

In set notation, the language accepted by the automaton is L={anb:n0}L = \{ a^{n}b : n \geq 0 \}.

Note that q2q_{2} has two self-loop edges, each with a different label. We write this compactly with multiple labels.

Linz Fig. 2.2: DFA Transition Graph with Trap State

Linz Fig. 2.2: DFA Transition Graph with Trap State

A trap state is a state from which the automaton can never "escape".

Note that q2q_{2} is a trap state in the dfa transition graph shown in Linz Figure 2.2.

Transition graphs are quite convenient for understanding finite automata.

For other purposes--such as representing finite automata in programs--a tabular representation of transition function δ\delta may also be convenient (as shown in Linz Fig. 2.3).

Linz Fig. 2.3: DFA Transition Table

Linz Fig. 2.3: DFA Transition Table

2.1.7 Linz Example 2.3

Find a deterministic finite accepter that recognizes the set of all string on Σ={a,b}\Sigma = \{a, b\} starting with the prefix abab.

Linz Figure 2.4 shows a transition graph for a dfa for this example.

Linz Fig. 2.4

Linz Fig. 2.4

The dfa must accept abab and then continue until the string ends.

This dfa has a final trap state q2q_{2} (accepts) and a non-final trap state q3q_{3} (rejects).

2.1.8 Linz Example 2.4

Find a dfa that accepts all strings on {0,1}\{ 0, 1 \}, except those containing the substring 001001.

Linz Figure 2.5 shows a dfa for this example.

Linz Fig. 2.5

Linz Fig. 2.5

Accepts: λ\lambda, 0, 00, 01, 010000

Rejects: 001, 000001, 0010101010101

2.1.9 Regular Languages

Linz Definition 2.3 (Regular Language): A language L is called regular if and only if there exists a dfa M such that L=L(M)L = L(M).

Thus dfas define the family of languages called regular.

2.1.10 Linz Example 2.5

Show that the language L={awa:w{a,b}*}L = \{ awa : w \in \{ a, b \}^{*}\} is regular.

Linz Figure 2.6 shows a dfa for this example.

Linz Fig. 2.6

Linz Fig. 2.6

Question: How would we prove that a languages is not regular?

We will come back to this question in chapter 4.

2.1.11 Linz Example 2.6

Let LL be the language in the previous example (Linz Example 2.5).

Show that L2L^{2} is regular.

L2={aw1aaw2a:w1,w2{a,b}*}L^{2} = \{ aw_{1}aaw_{2}a: w_{1}, w_{2} \in \{a,b\}^{*} \}.

Linz Figure 2.7 shows a dfa for this example.

Linz Fig. 2.7

Linz Fig. 2.7

The last example suggests the conjecture that if a language LL then so is L2L^2, L3L^3, etc.

We will come back to this issue in chapter 4.

2.2 Nondeterministic Finite Accepters

2.2.1 Nondeterministic Accepters

Linz Definition 2.4 (NFA): A nondeterministic finite accepter or nfa is defined by the tuple M=(Q,Σ,δ,q0,F)M = ( Q, \Sigma, \delta, q_{0}, F ) where QQ, Σ\Sigma, q0q_{0}, and FF are defined as for deterministic finite accepters, but

δ:Q×(Σ{λ})2Q\delta : Q \times (\Sigma \cup \{\lambda\}) \rightarrow 2^{Q}.

Remember for dfas:

The key differences between dfas and nfas are

  1. dfa: δ\delta yields a single state
    nfa: δ\delta yields a set of states

  2. dfa: consumes input on each move
    nfa: can move without input (λ\lambda)

  3. dfa: moves for all inputs in all states
    nfa: some situations have no defined moves

An nfa accepts a string if some possible sequence of moves ends in a final state.

An nfa rejects a string if no possible sequence of moves ends in a final state.

2.2.2 Linz Example 2.7

Consider the transition graph shown in Linz Figure 2.8.

Linz Fig. 2.8

Linz Fig. 2.8

Note the nondeterminism in state q0q_{0} with two possible transitions for input aa.

Also state q3q_{3} has no transition for any input.

2.2.3 Linz Example 2.8

Consider the transition graph for an nfa shown in Linz Figure 2.9.

Linz Fig. 2.9

Linz Fig. 2.9

Note the nondeterminism and the λ\lambda-transition.

Note: Here λ\lambda means the move takes place without consuming any input symbol. This is different from accepting an empty string.

Transitions:

Accepts: λ\lambda, 10, 1010, 101010

Rejects: 0, 11

2.2.4 Extended Transition Function for an NFA

As with dfas, the transition function can be extended so its second argument is a string.

Requirement: δ*(qi,w)=Qj\delta^{*}(q_{i},w) = Q_{j} where QjQ_{j} is the set of all possible states the automaton may be in, having started in state qiq_{i} and read string ww.

Linz Definition (Extended Transition Function): For an nfa, the extended transition function is defined so that δ*(qi,w)\delta^{*}(q_{i},w) contains qjq_{j} if there is a walk in the transition graph from qiq_{i} to qjq_{j} labelled ww.

2.2.5 Language Accepted by an NFA

Linz Definition 2.6 (Language Accepted by NFA): The language LL accepted by the nfa M=(Q,Σ,δ,q0,F)M = ( Q, \Sigma, \delta, q_{0}, F ) is defined

L(M)={wΣ*:δ*(q0,w)F}L(M) = \{ w \in \Sigma^{*} : \delta^{*}(q_{0}, w) \in F \neq \emptyset \}.

That is, L(M)L(M) is the set of all strings ww for which there is a walk labeled ww from the initial vertex of the transition graph to some final vertex.

2.2.6 Linz Example 2.10 (Example 2.8 Revisited)

Let's again examine the automaton given in Linz Figure 2.9 (Example 2.8).

Linz Fig. 2.9 (Repeated)

Linz Fig. 2.9 (Repeated)

This nfa, call it MM:

Note that q2q_{2} is a dead configuration because δ*(q0,110)=\delta^{*}(q_{0},110) = \emptyset.

2.2.7 Why Nondeterminism

When computers are deterministic?

2.3 Equivalence of DFAs and NFAs

2.3.1 Meaning of Equivalence

When are two mechanisms (e.g., programs) equivalent?

The last seems to be the best approach.

Linz Definition 2.7 (DFA-NFA Equivalence): Two finite accepters M1M_{1} and M2M_{2} are said to be equivalent if L(M1)=L(M2)L(M_{1}) = L(M_{2}). That is, if they both accept the same language.

Here "same language" refers to the input and "both accept" refers to the output.

Often there are many accepters for a language.

Thus there are many equivalent dfa and nfas.

2.3.2 Linz Example 2.11

Again consider the nfa represented by the graph in Linz Fig. 2.9. Call this M1M_{1}.