ACD Unit 1
ACD Unit 1
branch of Computer Science and Mathematics, which mainly deals with the
logic of computation with respect to simple machines, referred to as
automata.
Automata* enables scientists to understand how machines compute the
functions and solve problems. The main motivation behind developing
Automata Theory was to develop methods to describe and analyze the
dynamic behavior of discrete systems.
Automata originated from the word “Automaton” which is closely related to
“Automation”.
Basic Terminologies of Theory of Computation:
Now, let’s understand the basic terminologies, which are important and
frequently used in the Theory of Computation.
Symbol:
A symbol (often also called a character) is the smallest building block, which
can be any alphabet, letter, or picture.
Alphabets (Σ):
Alphabets are a set of symbols, which are always finite.
String:
A string is a finite sequence of symbols from some alphabet. A string is
generally denoted as w and the length of a string is denoted as |w|.
Empty string is the string with
zero occurrence of symbols,
represented as ε.
Number of Strings (of length 2)
that can be generated over the alphabet {a, b}:
- -
a a
a b
b a
b b
Grammar :
It is a finite set of formal rules for generating syntactically correct sentences or
meaningful correct sentences.
Constitute Of Grammar :
Grammar is basically composed of two basic elements –
1. Terminal Symbols –
Terminal symbols are those which are the components of the sentences
generated using a grammar and are represented using small case letter
like a, b, c etc.
2. Non-Terminal Symbols –
Non-Terminal Symbols are those symbols which take part in the
generation of the sentence but are not the component of the sentence.
Non-Terminal Symbols are also called Auxiliary Symbols and Variables.
These symbols are represented using a capital letter like A, B, C, etc.
Formal Definition of Grammar :
Any Grammar can be represented by 4 tuples – <N, T, P, S>
• N – Finite Non-Empty Set of Non-Terminal Symbols.
• T – Finite Set of Terminal Symbols.
• P – Finite Non-Empty Set of Production Rules.
• S – Start Symbol (Symbol from where we start producing our sentences
or strings).
Equivalent Grammars :
Grammars are said to be equivalent if they produce the same language.
Different Types Of Grammars :
Grammar can be divided on basis of –
• Type of Production Rules
• Number of Derivation Trees
• Number of Strings
DFA (Deterministic finite automata)
o DFA refers to deterministic finite automata. Deterministic refers to the
uniqueness of the computation. The finite automata are called deterministic
finite automata if the machine is read an input string one symbol at a time.
o In DFA, there is only one path for specific input from the current state to the
next state.
o DFA does not accept the null move, i.e., the DFA cannot change state without
any input character.
o DFA can contain multiple final states. It is used in Lexical Analysis in Compiler.
In the following diagram, we can see that from state q0 for input a, there is only one
path which is going to q1. Similarly, from q0, there is only one path for input b going
to q2.
1. δ: Q x ∑→Q
Graphical Representation of DFA
A DFA can be represented by digraphs called state diagram. In which:
Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}
Solution:
Transition Diagram:
Transition Table:
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
Example 2:
DFA with ∑ = {0, 1} accepts all starting with 0.
Solution:
Explanation:
o In the above diagram, we can see that on given 0 as input to DFA in state q0 the DFA
changes state to q1 and always go to final state q1 on starting input 0. It can accept
00, 01, 000, 001....etc. It can't accept any string which starts with 1, because it will never
go to final state on a string starting with 1.
Example 3:
DFA with ∑ = {0, 1} accepts all ending with 0.
Solution:
Explanation:
In the above diagram, we can see that on given 0 as input to DFA in state q0, the DFA
changes state to q1. It can accept any string which ends with 0 like 00, 10, 110,
100....etc. It can't accept any string which ends with 1, because it will never go to the
final state q1 on 1 input, so the string ending with 1, will not be accepted or will be
rejected.
In the following image, we can see that from state q0 for input a, there are two next
states q1 and q2, similarly, from q0 for input b, the next states are q0 and q1. Thus it
is not fixed or determined that with a particular input where to go next. Hence this FA
is called non-deterministic finite automata.
δ: Q x ∑ →2Q
where,
Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}
Solution:
Transition diagram:
Transition Table:
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
In the above diagram, we can see that when the current state is q0, on input 0, the
next state will be q0 or q1, and on 1 input the next state will be q1. When the current
state is q1, on input 0 the next state will be q2 and on 1 input, the next state will be
q0. When the current state is q2, on 0 input the next state is q2, and on 1 input the
next state will be q1 or q2.
Example 2:
NFA with ∑ = {0, 1} accepts all strings with 01.
Solution:
Transition Table:
→q0 q1 ε
q1 ε q2
*q2 q2 q2
Example 3:
NFA with ∑ = {0, 1} and accept all string of length atleast 2.
Solution:
Transition Table:
→q0 q1 q1
q1 q2 q2
*q2 ε ε
Conversion from NFA to DFA
In this section, we will discuss the method of converting NFA to its equivalent DFA. In
NFA, when a specific input is given to the current state, the machine goes to multiple
states. It can have zero, one or more than one move on a given input symbol. On the
other hand, in DFA, when a specific input is given to the current state, the machine
goes to only one state. DFA has only one move on a given input symbol.
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M). There should be
equivalent DFA denoted by M' = (Q', ∑', q0', δ', F') such that L(M) = L(M').
Step 2: Add q0 of NFA to Q'. Then find the transitions from this start state.
Step 3: In Q', find the possible set of states for each input symbol. If this set of states
is not in Q', then add it to Q'.
Step 4: In DFA, the final state will be all the states which contain F(final states of NFA)
Example 1:
Convert the given NFA to DFA.
Solution: For the given transition diagram we will first construct the transition table.
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
1. δ'([q0], 0) = [q0]
2. δ'([q0], 1) = [q1]
1. δ'([q2], 0) = [q2]
2. δ'([q2], 1) = [q1, q2]
The state [q1, q2] is the final state as well because it contains a final state q2. The
transition table for the constructed DFA will be:
State 0 1
Example 2:
Convert the given NFA to DFA.
State 0 1
Solution: For the given transition diagram we will first construct the transition table.
1. δ'([q1], 0) = ϕ
2. δ'([q1], 1) = [q0, q1]
Similarly,
As in the given NFA, q1 is a final state, then in DFA wherever, q1 exists that state
becomes a final state. Hence in the DFA, final states are [q1] and [q0, q1]. Therefore
set of final states F = {[q1], [q0, q1]}.
State 0 1
1. A = [q0]
2. B = [q1]
3. C = [q0, q1]
Minimization of DFA
Minimization of DFA means reducing the number of states from given FA. Thus, we
get the FSM(finite state machine) with redundant states after minimizing the FSM.
We have to follow the various steps to minimize the DFA. These are as follows:
Step 1: Remove all the states that are unreachable from the initial state via any set of
the transition of DFA.
Step 3: Now split the transition table into two tables T1 and T2. T1 contains all final
states, and T2 contains non-final states.
1. δ (q, a) = p
2. δ (r, a) = p
That means, find the two states which have the same value of a and b and remove one
of them.
Step 5: Repeat step 3 until we find no similar rows available in the transition table T1.
Step 7: Now combine the reduced T1 and T2 tables. The combined transition table is
the transition table of minimized DFA.
Example:
Solution:
Step 1: In the given DFA, q2 and q4 are the unreachable states so remove them.
Step 2: Draw the transition table for the rest of the states.
State 0 1
→q0 q1 q3
q1 q0 q3
*q3 q5 q5
*q5 q5 q5
Step 3: Now divide rows of transition table into two sets as:
1. One set contains those rows, which start from non-final states:
State 0 1
q0 q1 q3
q1 q0 q3
2. Another set contains those rows, which starts from final states.
State 0 1
q3 q5 q5
q5 q5 q5
Step 5: In set 2, row 1 and row 2 are similar since q3 and q5 transit to the same state
on 0 and 1. So skip q5 and then replace q5 by q3 in the rest.
State 0 1
q3 q3 q3
→q0 q1 q3
q1 q0 q3
*q3 q3 q3
Regular Expression
o The language accepted by finite automata can be easily described by simple
expressions called Regular Expressions. It is the most effective way to represent any
language.
o The languages accepted by some regular expression are referred to as Regular
languages.
o A regular expression can also be described as a sequence of pattern that defines a
string.
o Regular expressions are used to match character combinations in strings. String
searching algorithm used this pattern to find the operations on a string.
For instance:
In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx,
xxx, xxxx, .....}
Regular Languages
Regular languages are formal languages that regular expressions
can describe and can also be recognized by finite automata. They are
used to define sets of strings, such as sequences of characters or
words, that follow specific patterns.
They are important in computer science and theoretical computer
science because they form a foundation for understanding the theory of
computation and the design of compilers and other software tools.
Union: If L and M are two regular languages then their union L U M is also a union.
1. L U M = {s | s is in L or s is in M}
Intersection: If L and M are two regular languages then their intersection is also an
intersection.
1. L ⋂ M = {st | s is in L and t is in M}
Kleen closure: If L is a regular language then its Kleen closure L1* will also be a regular
language.