You are on page 1of 40

Example

Let us formally specify a DFA that accepts all and only the
strings of 0’s and 1’s that have the sequence 01
somewhere in the string.
We can write this language L as:
{w | w is of the form x01y for some strings x and y
consisting of 0’s and 1’s only.}
Another equivalent description, using parameters x and y
to the left of the vertical bar, is:
{x01y | x and y are any strings of 0’s and 1’s}

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 9 / 129


Example

Let us formally specify a DFA that accepts all and only the
strings of 0’s and 1’s that have the sequence 01
somewhere in the string.
We can write this language L as:
{w | w is of the form x01y for some strings x and y
consisting of 0’s and 1’s only.}
Another equivalent description, using parameters x and y
to the left of the vertical bar, is:
{x01y | x and y are any strings of 0’s and 1’s}

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 9 / 129


Example

Let us formally specify a DFA that accepts all and only the
strings of 0’s and 1’s that have the sequence 01
somewhere in the string.
We can write this language L as:
{w | w is of the form x01y for some strings x and y
consisting of 0’s and 1’s only.}
Another equivalent description, using parameters x and y
to the left of the vertical bar, is:
{x01y | x and y are any strings of 0’s and 1’s}

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 9 / 129


Example — continued
{x01y | x and y are any strings of 0’s and 1’s}
Examples of strings in the language include 01, 11010,
and 100011.
Examples of strings not in the language include ǫ, 0, and
111000.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 10 / 129


Example — continued
{x01y | x and y are any strings of 0’s and 1’s}
What do we know about an automaton that can accept this
language L?

Known Points

Its input alphabet is Σ = {0, 1}.


It has some set of states, Q, of which one, say
q0 , is the start state.
This automaton has to remember the
important facts about what inputs it has seen
so far.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 10 / 129


Example — continued
{x01y | x and y are any strings of 0’s and 1’s}

To decide whether 01 is a substring of the input, A needs to


remember:
1. Has it already seen 01? If so, then it accepts every sequence of
further inputs; i.e., it will only be in accepting states from now on.

1110101001111
2. Has it never seen 01, but its most recent input was 0, so if it now
sees 1, it will have seen 01 and can accept everything it sees
from here on?

1110101001111
3. Has it never seen 01, but its last input was either nonexistent (it
just started) or it last saw a 1? In this case, A cannot accept until
it first sees a 0 and then sees a 1 immediately after.
↓ ↓
1110101001111 or 1110101001111
Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 10 / 129
Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


1. Has it already seen 01? If so, then it accepts every sequence of further inputs; i.e., it will
only be in accepting states from now on.
2. Has it never seen 01, but its most recent input was 0, so if it now sees 1, it will have seen 01
and can accept everything it sees from here on?
3. Has it never seen 01, but its last input was either nonexistent (it just started) or it last saw a
1? In this case, A cannot accept until it first sees a 0 and then sees a 1 immediately after.

These three conditions can each be represented by a


state.
Condition (3) represented by the start state, q0 .
Surely, when just starting, we need to see a 0 and then a 1.
But, if in state q0 we next see a 1, then we are no closer to
string 01, and so we must stay in state q0 .
That is, δ(q0 , 1) = q0 .

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 11 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


1. Has it already seen 01? If so, then it accepts every sequence of further inputs; i.e., it will
only be in accepting states from now on.
2. Has it never seen 01, but its most recent input was 0, so if it now sees 1, it will have seen 01
and can accept everything it sees from here on?
3. Has it never seen 01, but its last input was either nonexistent (it just started) or it last saw a
1? In this case, A cannot accept until it first sees a 0 and then sees a 1 immediately after.

However, if we are in state q0 and we next see a 0, we are


in condition (2).
That is, we have never seen 01, but we have our 0.
Thus, let us use q2 to represent condition (2).
Our transition from q0 on input 0 is δ(q0 , 0) = q2

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 11 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


1. Has it already seen 01? If so, then it accepts every sequence of further inputs; i.e., it will
only be in accepting states from now on.
2. Has it never seen 01, but its most recent input was 0, so if it now sees 1, it will have seen 01
and can accept everything it sees from here on?
3. Has it never seen 01, but its last input was either nonexistent (it just started) or it last saw a
1? In this case, A cannot accept until it first sees a 0 and then sees a 1 immediately after.

Now, let us consider the transitions from state q2 .


If we see a 0, we are no better off than we were, but no
worse either.
We have not seen 01, but 0 was the last symbol, so we are
still waiting for a 1.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 11 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


1. Has it already seen 01? If so, then it accepts every sequence of further inputs; i.e., it will
only be in accepting states from now on.
2. Has it never seen 01, but its most recent input was 0, so if it now sees 1, it will have seen 01
and can accept everything it sees from here on?
3. Has it never seen 01, but its last input was either nonexistent (it just started) or it last saw a
1? In this case, A cannot accept until it first sees a 0 and then sees a 1 immediately after.

State q2 describes this situation perfectly, so we want


δ(q2 , 0) = q2 .
If we are in state q2 and we see a 1 input, we now know
there is a 0 followed by a 1.
We can go to an accepting state, which we shall call q1 ,
and which corresponds to condition (1) above.
That is δ(q2 , 1) = q1 .

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 11 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


1. Has it already seen 01? If so, then it accepts every sequence of further inputs; i.e., it will
only be in accepting states from now on.
2. Has it never seen 01, but its most recent input was 0, so if it now sees 1, it will have seen 01
and can accept everything it sees from here on?
3. Has it never seen 01, but its last input was either nonexistent (it just started) or it last saw a
1? In this case, A cannot accept until it first sees a 0 and then sees a 1 immediately after.

Finally, we must design the transitions for state q1 .


In this state, we have already seen a 01 sequence, so
regardless of what happens, we shall still be a situation
where we’ve seen 01.
That is, δ(q1 , 0) = δ(q1 , 1) = q1 .

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 11 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


Thus, Q = {q0 , q1 , q2 }.
As we said, q0 is the start state, and the only accepting
state is q1 ; that is, F = {q1 }.
The complete specification of the automaton A that accepts
the language L of strings that have a 01 substring, is

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 })

where δ ts the transition function described above.


A = (Q, Σ, δ, q0 , F )

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 12 / 129


Example — continued

{x01y | x and y are any strings of 0’s and 1’s}


Thus, Q = {q0 , q1 , q2 }.
As we said, q0 is the start state, and the only accepting
state is q1 ; that is, F = {q1 }.
The complete specification of the automaton A that accepts
the language L of strings that have a 01 substring, is

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 })

where δ ts the transition function described above.


A = (Q, Σ, δ, q0 , F )

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 12 / 129


Simpler Notations for DFA’s

A = (Q, Σ, δ, q0 , F )
Specifying a DFA as a five-tuple with a detailed description
of the δ transition function is both tedious and hard to read.
There are two preferred notations for describing automata:

1. A transition diagram, which is a graph.


2. A transition table, which is a tabular listing of the δ
function, which by implication tells us the set of states
and the input alphabet.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 13 / 129


Simpler Notations for DFA’s

A = (Q, Σ, δ, q0 , F )
Specifying a DFA as a five-tuple with a detailed description
of the δ transition function is both tedious and hard to read.
There are two preferred notations for describing automata:

1. A transition diagram, which is a graph.


2. A transition table, which is a tabular listing of the δ
function, which by implication tells us the set of states
and the input alphabet.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 13 / 129


Simpler Notations for DFA’s

A = (Q, Σ, δ, q0 , F )
Specifying a DFA as a five-tuple with a detailed description
of the δ transition function is both tedious and hard to read.
There are two preferred notations for describing automata:

1. A transition diagram, which is a graph.


2. A transition table, which is a tabular listing of the δ
function, which by implication tells us the set of states
and the input alphabet.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 13 / 129


Transition Diagrams

A transition diagram for a DFA A = (Q, Σ, δ, q0 , F ) is a graph


defined as follows:
a) For each state in Q there is a node.
b) For each state q in Q and each input symbol a in Σ, let
δ(q, a) = p.
Then the transition diagram has an arc from node q to
node p, labeled a.
If there are several input symbols that cause transitions
from q to p, then the transition diagram can have one
arc, labeled by the list of these symbols.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 14 / 129


Transition Diagrams

A transition diagram for a DFA A = (Q, Σ, δ, q0 , F ) is a graph


defined as follows:
c) There is an arrow into the start state q0 , labeled Start.
This arrow does not originate at any node.
d) Nodes corresponding to accepting states (those in F ) are
marked by a double circle.
States not in F have a single circle.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 14 / 129


Example

Figure shows the transition diagram for the DFA that we


designed in the previous example.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 15 / 129


Example — continued

a) For each state in Q there is a node.

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }), δ(q0 , 0) = q2 , δ(q0 , 1) = q0 ,


δ(q2 , 0) = q2 , δ(q2 , 1) = q1 , δ(q1 , 0) = δ(q1 , 1) = q1

We see in that diagram the three nodes that correspond to the


three states.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 16 / 129


Example — continued

b) For each state q in Q and each input symbol a in Σ, let δ(q, a) = p. Then the
transition diagram has an arc from node q to node p, labeled a. If there are several
input symbols that cause transitions from q to p, then the transition diagram can
have one arc, labeled by the list of these symbols.

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }), δ(q0 , 0) = q2 , δ(q0 , 1) = q0 ,


δ(q2 , 0) = q2 , δ(q2 , 1) = q1 , δ(q1 , 0) = δ(q1 , 1) = q1

Out of each state is one arc labeled 0 and one arc labeled 1.
The two arcs are combined into one with a double label in the
case of q1 .

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 16 / 129


Example — continued

c) There is an arrow into the start state q0 , labeled Start. This arrow does not
originate at any node.

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }), δ(q0 , 0) = q2 , δ(q0 , 1) = q0 ,


δ(q2 , 0) = q2 , δ(q2 , 1) = q1 , δ(q1 , 0) = δ(q1 , 1) = q1

There is a Start arrow entering the start state, q0 , and the one
accepting state, q1 , is represented by a double circle.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 16 / 129


Example — continued

d) Nodes corresponding to accepting states (those in F ) are marked by a double


circle. States not in F have a single circle.

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }), δ(q0 , 0) = q2 , δ(q0 , 1) = q0 ,


δ(q2 , 0) = q2 , δ(q2 , 1) = q1 , δ(q1 , 0) = δ(q1 , 1) = q1

There is a Start arrow entering the start state, q0 , and the one
accepting state, q1 , is represented by a double circle.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 16 / 129


Transition Tables

A transition table is a conventional, tabular representation


of a function like δ that, takes two arguments and returns a
value.
The rows of the table correspond to the states. and the
columns correspond to the inputs.
The entry for the row corresponding to state q and the
column corresponding to input a is the state δ(q, a).

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 17 / 129


Example

The transition table corresponding to the function δ of previous


example is shown in the figure.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 18 / 129


Example — continued

A = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }), δ(q0 , 0) = q2 , δ(q2 , 0) = q2 ,


δ(q2 , 1) = q1 , δ(q1 , 0) = δ(q1 , 1) = q1

The start state is marked with an arrow.


The accepting states are marked with a star.
We can deduce the sets of states and input
symbols by looking at the row and column
heads.
We can now read from the transition table all
the information we need to specify the finite
automata uniquely.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 19 / 129


Extending the Transition Function to Strings

DFA defines a language.


The language is the set of all strings that result in a
sequence of state transitions from the start state to an
accepting state.
In terms of the transition diagram, the language of a DFA is
the set of labels along all the paths that lead from the start
state to any accepting state.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 20 / 129


Extending the Transition Function to Strings

DFA defines a language.


The language is the set of all strings that result in a
sequence of state transitions from the start state to an
accepting state.
In terms of the transition diagram, the language of a DFA is
the set of labels along all the paths that lead from the start
state to any accepting state.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 20 / 129


Extending the Transition Function to Strings

DFA defines a language.


The language is the set of all strings that result in a
sequence of state transitions from the start state to an
accepting state.
In terms of the transition diagram, the language of a DFA is
the set of labels along all the paths that lead from the start
state to any accepting state.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 20 / 129


Extending the . . . to Strings — continued

We need to make the notion of the language of a DFA


precise.
We define an extended transition function.
The extended transition function describes what happens
when we start in any state and follow any sequence of
inputs.
If δ is our transition function, then the extended transition
function constructed from δ will be called δ̂.
The extended transition function is a function that takes a
state q and a string w and returns a state p.
This state is the state that the automaton reaches when
starting in state q and processing the sequence of inputs
w.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 21 / 129


Extending the . . . to Strings — continued

We need to make the notion of the language of a DFA


precise.
We define an extended transition function.
The extended transition function describes what happens
when we start in any state and follow any sequence of
inputs.
If δ is our transition function, then the extended transition
function constructed from δ will be called δ̂.
The extended transition function is a function that takes a
state q and a string w and returns a state p.
This state is the state that the automaton reaches when
starting in state q and processing the sequence of inputs
w.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 21 / 129


Extending the . . . to Strings — continued

We need to make the notion of the language of a DFA


precise.
We define an extended transition function.
The extended transition function describes what happens
when we start in any state and follow any sequence of
inputs.
If δ is our transition function, then the extended transition
function constructed from δ will be called δ̂.
The extended transition function is a function that takes a
state q and a string w and returns a state p.
This state is the state that the automaton reaches when
starting in state q and processing the sequence of inputs
w.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 21 / 129


Extending the . . . to Strings — continued

We need to make the notion of the language of a DFA


precise.
We define an extended transition function.
The extended transition function describes what happens
when we start in any state and follow any sequence of
inputs.
If δ is our transition function, then the extended transition
function constructed from δ will be called δ̂.
The extended transition function is a function that takes a
state q and a string w and returns a state p.
This state is the state that the automaton reaches when
starting in state q and processing the sequence of inputs
w.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 21 / 129


Extending the . . . to Strings — continued

We define δ̂ by induction on the length of the input string, as


follows:

BASIS: δ̂(q, ǫ) = q.
That is, if we are in state q and read no
inputs, then we are still in state q.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 22 / 129


Extending the . . . to Strings — continued

We define δ̂ by induction on the length of the input string, as


follows:
INDUCTION: Suppose w is a string of the form xa.
That is, a is the last symbol of w.
And x is the string consisting of all but the last
symbol.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 22 / 129


Extending the . . . to Strings — continued
For example, w = 1101 is broken into x = 110 and a = 1.
Then
δ̂(q, w) = δ(δ̂(q, x), a)
i.e.
δ̂(q, 1101) = δ(δ̂(q, 110), 1)

To compute δ̂(q, w), first compute δ̂(q, x).


This is the state that the automaton is in after processing
all but the last symbol of w.
Suppose this state is p; that is, δ̂(q, x) = p.
Then δ̂(q, w) is what we get by making a transition from
state p on input a, the last symbol of w.
That is, δ̂(q, w) = δ(p, a).
Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 23 / 129
Extending the . . . to Strings — continued
For example, w = 1101 is broken into x = 110 and a = 1.
Then
δ̂(q, w) = δ(δ̂(q, x), a)
i.e.
δ̂(q, 1101) = δ(δ̂(q, 110), 1)

To compute δ̂(q, w), first compute δ̂(q, x).


This is the state that the automaton is in after processing
all but the last symbol of w.
Suppose this state is p; that is, δ̂(q, x) = p.
Then δ̂(q, w) is what we get by making a transition from
state p on input a, the last symbol of w.
That is, δ̂(q, w) = δ(p, a).
Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 23 / 129
Extending the . . . to Strings — continued
For example, w = 1101 is broken into x = 110 and a = 1.
Then
δ̂(q, w) = δ(δ̂(q, x), a)
i.e.
δ̂(q, 1101) = δ(δ̂(q, 110), 1)

To compute δ̂(q, w), first compute δ̂(q, x).


This is the state that the automaton is in after processing
all but the last symbol of w.
Suppose this state is p; that is, δ̂(q, x) = p.
Then δ̂(q, w) is what we get by making a transition from
state p on input a, the last symbol of w.
That is, δ̂(q, w) = δ(p, a).
Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 23 / 129
Example

Let us design a DFA to accept the language L = {w | w has


both an even number of 0’s and an even number of 1’s}

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 24 / 129


Example — continued

L = {w | w has both an even number of 0’s and an even


number of 1’s}
The job of the states of this DFA is to count both the
number of 0’s and the number of 1’s.
It counts them modulo 2.
That is, the state is used to remember
Whether the number of 0’s seen so far is even or odd.
And also to remember whether the number of 1’s seen
so far is even or odd.

Dr. Muhammad Masroor Ali CSE 211 (Theory of Computation) 25 / 129

You might also like