Toc Unit I.2
Toc Unit I.2
q₀: Initial state. Represents the scenario where no part of the substring ‘101’ has been
identified yet.
q₁: Represents that the input has ended with ‘1’.
q₂: Represents that the input has ended with ’10’.
q₃: Accept state. Represents that the substring ‘101’ has been detected.
q₃: The state where the DFA ends if the input string contains '101'.
These rules define how the DFA moves between states based on the input:
δ(q₀, '1') = q₁
δ(q₀, '0') = q₀
δ(q₁, '0') = q₂
δ(q₁, '1') = q₁
δ(q₂, '1') = q₃
δ(q₂, '0') = q₀
δ(q₃, '0') = q₃
δ(q₃, '1') = q₃
State Diagram
Example 2: DFA for Even Length Inputs
Let’s create a DFA to recognise strings over the alphabet Σ = {a, b} that have an even
length.
q₀: The state where the DFA ends if the string has an even number of characters.
δ(q₀, 'a') = q₁
δ(q₀, 'b') = q₁
δ(q₁, 'a') = q₀
δ(q₁, 'b') = q₀
State Diagram
Let’s create a DFA to recognise strings over the alphabet Σ = {a, b} where ‘a’ and ‘b’
strictly alternate.
q₀: Initial state. Represents an empty string or one that follows the alternating pattern.
q₁: Represents that the string ends with ‘a’ and is expecting ‘b’.
q₂: Represents that the string ends with ‘b’ and is expecting ‘a’.
q₀: The state where the DFA ends if the alternating pattern is preserved.
These rules define how the DFA moves between states based on the input:
δ(q₀, 'a') = q₁
δ(q₀, 'b') = q₂
δ(q₁, 'a') = q₁
δ(q₁, 'b') = q₀
δ(q₂, 'a') = q₀
δ(q₂, 'b') = q₂
State Diagram
Applications of DFA
In NDFA, for a particular input symbol, the machine can move to any combination of
the states in the machine. In other words, the exact state to which the machine moves
cannot be determined. Hence, it is called Non-deterministic Automaton. As it has
finite number of states, the machine is called Non-deterministic Finite
Machine or Non-deterministic Finite Automaton.
q0 is the initial state from where any input is processed (q0 ∈ Q).
transition can occur to any combination of Q states)
Example
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F = {c}
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
Each transition leads to exactly one A transition leads to a subset of states i.e.
state called as deterministic some transitions can be non-deterministic.
Accepts input if one of the last states is in
Accepts input if the last state is in Final
Final.
Backtracking is allowed in DFA. Backtracking is not always possible.
Requires more space. Requires less space.
Empty string transitions are not seen in
Permits empty string transition.
DFA.
For a given state, on a given input we For a given state, on a given input we reach
reach a deterministic and unique state. more than one state.
Need to convert NFA to DFA in the design
DFA is a subset of NFA.
of a compiler.
δ:Q×Σ→Q δ : Q × Σ → 2Q
For example − δ(q0,a)={q1} For example − δ(q0,a)={q1,q2}
DFA is more difficult to construct. NFA is easier to construct.
NFA is understood as multiple small
DFA is understood as one machine.
machines computing at the same time.
Deterministic Finite Automata Non-Deterministic Finite Automata
Acceptor (Recognizer)
An automaton that computes a Boolean function is called an acceptor. All the states
of an acceptor is either accepting or rejecting the inputs given to it.
Classifier
A classifier has more than two final states and it gives a single output when it
terminates.
Transducer
An automaton that produces outputs based on current input and/or previous state is
called a transducer. Transducers can be of two types −
Mealy Machine − The output depends both on the current state and the current input.
Moore Machine − The output depends only on the current state.
A string is accepted by a DFA/NDFA iff the DFA/NDFA starting at the initial state
ends in an accepting state (any of the final states) after reading the string wholly.
δ*(q0, S) ∈ F
{S | S ∈ ∑* and δ*(q0, S) ∈ F}
δ*(q0, S′) ∉ F
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the acceptable strings
can be derived.
Strings accepted by the above DFA: {0, 00, 11, 010, 101, ...........}
Strings not accepted by the above DFA: {1, 011, 111, ........}
Example 1:
Transition diagram:
Transition Table:
Example 2:
Solution:
Transition Table:
Example 3:
Solution:
Transition Table:
Present State 0 1
→q0 q0, q1 q0, q2
q1 q3 Ε
q2 q2, q3 q3
→q3 q3 q3
Solution:
The transition diagram can be drawn by using the mapping function as given in the
table.
Here,
Example 2:
Design an NFA with ∑ = {0, 1} accepts all string ending with 01.
Solution:
Hence, NFA would be:
Example 3:
Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'.
Solution:
Advertisement
Then,
Now before double 1, there can be any string of 0 and 1. Similarly, after double 0,
there can be any string of 0 and 1.
. q0 → q1 → q2 → q3 → q4 → q4 → q4 → q4
Example 4:
Solution:
The language consists of all the string containing substring 1010. The partial
transition diagram can be:
Now as 1010 could be the substring. Hence we will add the inputs 0's and 1's so that
the substring 1010 of the language can be maintained. Hence the NFA becomes:
Transition table for the above transition diagram can be given below:
Present State 0 1
→q1 q1 q1, q2
q2 q3
q3 q4
q4 q5
*q5 q5 q5
Consider a string 111010,
Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol from the
right end is always 0.
Solution:
Thus we get the third symbol from the right end as '0' always. The NFA can be:
The above image is an NFA because in state q0 with input 0, we can either go to state
q0 or q1.