Unit 6 - Final
Unit 6 - Final
Unit 6
Unit 6
Structure
6.1
Introduction
Objectives
6.2
Basic Terms
6.3
6.4
6.5
6.6
Summary
6.7
Terminal Questions
6.8
Answers
6.1 Introduction
A study of finite automaton is their applicability to the design of several
common types of computer algorithms and programs. For example, the
lexical analysis phase of a compiler (in which program units such as begin
and + are identified) is often based on the simulation of a finite automaton.
Also, the problem of finding an occurrence of a string within another, for
example, whether any of the strings air, water, earth, and fire occur in the
text of Elements of the Theory of Computation, can also be solved efficiently
by methods originating from the theory of finite automata.
Unit 6
Unit 6
Unit 6
It is clear from this diagram that, the DFA is represented using circles,
arrows and arcs labeled with some digits, concentric circles etc. The circles
are nothing but the states of DFA. In the DFA shown in figure, there are
three states viz., q0, q1 and q2. An arrow enters into state q0 and is not
originating from any state and so it is quite different from other states and is
called the start state or initial state. The state q2 has two concentric circles
and is also a special state called the final state or accepting state. In this
DFA, there is, only one final state. Based on the language accepted by DFA,
there can be more than one final state also.
The states other than start state and final states are called intermediate
Sikkim Manipal University
Unit 6
states. Always the machine initially will be in the start state. It is clear from
the figure that, the machine in state q0, after accepting the symbol 0, stays in
state q0 and after accepting the symbol 1, the machine enters into state q 1.
Whenever the machine enters from one state to another state, we say that
there is a transition from one state to another state. Here we can say that
there is a transition from state q0 to q1 on input symbol 1.
In state q1, on input symbol 0, the machine will stay in q1 and on symbol 1,
there is a transition to state q2. In state q2, on input symbol 0 or 1, the
machine stays in state q2 only. This DFA has three states q0, q1 and q2 and
can be represented as Q = {q0, q1, q2}, the possible input symbols set = {0,
1}, which is set of input symbols (alphabets) for the machine.
There will be a transition from one state to another based on the input
alphabets. If there is a transition from vi, to vj on an input symbol a, it can be
represented as (vi, a) = vj.
The transitions from each state of the machine shown in figure based on the
input alphabets {0, 1} are shown in table.
State
q0
q0
q1
q1
q2
q2
input
0
1
0
1
0
1
Output
q0
q1
q1
q2
q2
q2
Transition Representation
(q0, 0) = q0
(q0, 1) = q1
(q1, 0) = q1
(q1, 1) = q2
(q2, 0) = q2
(q2, 1) = q2
Unit 6
The directed edges from the initial state to the final state are labeled as
input/output.
6.4.1 Example
The graph represents the DFA,
Unit 6
states, there are three rows for each state. The input symbols are only 0
and 1 so, there are two columns for the input symbols. The transitional
table for the diagram is given below.
Unit 6
the machine stays in state q1 which is not a final state. Therefore the string
0100 is rejected by the machine.
6.5.1 Definition
Let M = (Q, , , q0, F) be a DFA where
Q is non-empty, finite set of states.
is a non-empty, finite set of input alphabets.
is a transition function, which is a mapping from Q to Q. For this
transition function the parameters to be passed are state and input symbol.
Based on the current state and input symbol, the machine may enter into
another state.
q0 Q is the start (or initial) state.
F Q is set of accepting or final states.
The string (also called language) w accepted by a DFA can be defined as
follows.
(For example, in the above figure, (q0, 1) = q1 and (q1, 1) = q2. So, (q0,
11) = q2).
Unit 6
6.5.2 Properties
6.5.3 Example
Solution:
Property 1: This means that when the current state of the machine is q and
when there is no input ( means no input), the machine will not move to any
new state, instead, it stays in the same state q.
6.5.4 Example
Obtain a DFA to accept strings of as and bs starting with the string ab.
Solution: It is clear that the string should start with ab and so, the minimum
Sikkim Manipal University
Unit 6
where q2 is the final or accepting state. In state q0, if the input symbol is b,
the machine should reject b (note that the string should start with a). So, in
state q0, on input b, we enter into the rejecting state q3. The machine for this
can be of the form
The machine will be in state q1, if the first input symbol is a. If this a is
followed by another a, the string aa should be rejected by the machine. So,
in state q1, if the input symbol is a, we reject it and enter into q3 which is the
rejecting state. The machine for this can be of the form
Unit 6
Whenever the string is not starting with ab, the machine will be in state q3
which is the rejecting state. So, in state q 3, if the input string consists of as
and bs of any length, the entire string can be rejected and can stay in state
q3 only.
The resulting machine can be of the form
The machine will be in state q2, if the input string starts with ab. After the
string ab, the string containing any combination of as and bs, can be
accepted and so remain in state q2 only. The complete machine to accept
the strings of as and bs starting with the string ab is shown in figure.
The state q3 is called trap state or rejecting state.
Unit 6
Unit 6
Unit 6
6.5.7 Example
Obtain a DFA to accept even number of as, and odd number of as.
Sikkim Manipal University
Unit 6
Consider the string aaa: (q0, aaa) = ( (q0, aa), a) = ( ( (q0, a), a),
a) = ( (q1, a), a) = (q0, a) = q1, which is an acceptable state.
6.5.8 Problem
Obtain DFA to accept strings of as and bs having exactly one a, at least
one a, not more than three as.
Solution:
To accept exactly one a:
To accept exactly one a, we need two states q0 and q1 and make q1 as the
final state. The machine to accept one a is shown below.
In q0, on input symbol b, remain q0 only so that any number of bs can end
Sikkim Manipal University
Unit 6
In q1, on input symbol b, remains q1 then machine can take the form
But, in state q1, if the input symbol is a, the string has to be rejected as the
machine can have any number of bs but exactly one a. So, the string has to
be rejected and we enter into a trap state q2. Once the machine enters into
trap state, there is no way to come out of the state and the string is rejected
by the machine. The complete machine is shown in the figure.
Unit 6
The machine to accept at least one a: The minimum string that can be
accepted by the machine is a. For this, we need two states q0 and q1 where
q1 is the final state. The machine for this is shown below.
In state q0, if the input symbol is b, remain in q0. Once the final state q1is
reached, whether the input symbol is a or b, the entire string has to be
accepted. The machine to accept at least one a is shown in fig.
Unit 6
The machine to accept not more than three as: The machine should accept
not more than three as means,
It can accept zero as
It can accept one a
It can accept two as
It can accept 3 as
But, it cannot accept more than three as.
In this machine maximum of three as can be accepted (that is, the machine
can accept zero as, one a, two as). So, we need maximum four states q 0,
q1, q2 and q3 where all these states are final states and q0 is the start state.
In state q3, if the input symbol is a, the string has to be rejected and we
enter into a trap state q4. Once this trap state is reached, whether the input
symbol is a or b, the entire string has to be rejected and remain in state q 4.
Now, the machine can take the form as shown below.
Unit 6
In state q0, q1, q2 and q3, if the input symbol is b, stay in their respective
states and the final transition diagram is shown below.
Unit 6
6.5.9 Problem
Unit 6
(ii)
(iii)
(iv)
6.6 Summary
The concept of finite automata is used in wide applications. Large natural
vocabularies can be described using finite automaton which includes the
applications such as spelling checkers and advisers, multi-language
dictionaries, to indent and documents, in calculators to evaluate complex
expressions based on the priority of an operator etc. In this unit we gave a
comprehensive idea about the DFA and a graphical representation of DFA.
Further we discuss the language accepted by DFA with certain examples.
Unit 6
6.8 Answers
Sikkim Manipal University
Unit 6
Unit 6