0% found this document useful (0 votes)
120 views20 pages

ACD Unit 1

Uploaded by

Vivek Vaibhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views20 pages

ACD Unit 1

Uploaded by

Vivek Vaibhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Automata theory (also known as Theory Of Computation) is a theoretical

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

Length of String |w| = 2


Number of Strings = 4
Conclusion:
For alphabet {a, b} with length n, number of
strings can be generated = 2n.
Note: If the number of symbols in the alphabet Σ is represented by |Σ|, then a
number of strings of length n, possible over Σ is |Σ|n.

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.

Formal Definition of DFA


A DFA is a collection of 5-tuples same as we described in the definition of FA.

1. Q: finite set of states


2. ∑: finite set of the input symbol
3. q0: initial state
4. F: final state
5. δ: Transition function

Transition function can be defined as:

1. δ: Q x ∑→Q
Graphical Representation of DFA
A DFA can be represented by digraphs called state diagram. In which:

1. The state is represented by vertices.


2. The arc labeled with an input character show the transitions.
3. The initial state is marked with an arrow.
4. The final state is denoted by a double circle.

Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}

Solution:

Transition Diagram:

Transition Table:

Present State Next state for Input 0 Next State of Input 1

→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.

NFA (Non-Deterministic finite automata)


o NFA stands for non-deterministic finite automata. It is easy to construct an NFA than
DFA for a given regular language.
o The finite automata are called NFA when there exist many paths for specific input from
the current state to the next state.
o Every NFA is not DFA, but each NFA can be translated into DFA.
o NFA is defined in the same way as DFA but with the following two exceptions, it
contains multiple next states, and it contains ε transition.

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.

Formal definition of NFA:


NFA also has five states same as DFA, but with different transition function, as shown
follows:

δ: Q x ∑ →2Q

where,

1. Q: finite set of states


2. ∑: finite set of the input symbol
3. q0: initial state
4. F: final state
5. δ: Transition function
Graphical Representation of an NFA
An NFA can be represented by digraphs called state diagram. In which:

1. The state is represented by vertices.


2. The arc labeled with an input character show the transitions.
3. The initial state is marked with an arrow.
4. The final state is denoted by the double circle.

Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}

Solution:

Transition diagram:

Transition Table:

Present State Next state for Input 0 Next State of Input 1

→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:

Present State Next state for Input 0 Next State of Input 1

→q0 q1 ε

q1 ε q2

*q2 q2 q2

Example 3:
NFA with ∑ = {0, 1} and accept all string of length atleast 2.

Solution:

Transition Table:

Present State Next state for Input 0 Next State of Input 1

→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').

Steps for converting NFA to DFA:


Step 1: Initially Q' = ϕ

Step 2: Add q0 of NFA to Q'. Then find the transitions from this start state.

Backward Skip 10sPlay VideoForward Skip 10s

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

*q2 q2 {q1, q2}

Now we will obtain δ' transition for state q0.

1. δ'([q0], 0) = [q0]
2. δ'([q0], 1) = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = [q1, q2] (new state generated)


2. δ'([q1], 1) = [q1]

The δ' transition for state q2 is obtained as:

1. δ'([q2], 0) = [q2]
2. δ'([q2], 1) = [q1, q2]

Now we will obtain δ' transition on [q1, q2].

1. δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)


2. = {q1, q2} ∪ {q2}
3. = [q1, q2]
4. δ'([q1, q2], 1) = δ(q1, 1) ∪ δ(q2, 1)
5. = {q1} ∪ {q1, q2}
6. = {q1, q2}
7. = [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

→[q0] [q0] [q1]

[q1] [q1, q2] [q1]

*[q2] [q2] [q1, q2]

*[q1, q2] [q1, q2] [q1, q2]

The Transition diagram will be:

The state q2 can be eliminated because q2 is an unreachable state.

Example 2:
Convert the given NFA to DFA.
State 0 1

→q0 {q0, q1} {q1}

*q1 ϕ {q0, q1}

Solution: For the given transition diagram we will first construct the transition table.

Now we will obtain δ' transition for state q0.

1. δ'([q0], 0) = {q0, q1}


2. = [q0, q1] (new state generated)
3. δ'([q0], 1) = {q1} = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = ϕ
2. δ'([q1], 1) = [q0, q1]

Now we will obtain δ' transition on [q0, q1].

1. δ'([q0, q1], 0) = δ(q0, 0) ∪ δ(q1, 0)


2. = {q0, q1} ∪ ϕ
3. = {q0, q1}
4. = [q0, q1]

Similarly,

1. δ'([q0, q1], 1) = δ(q0, 1) ∪ δ(q1, 1)


2. = {q1} ∪ {q0, q1}
3. = {q0, q1}
4. = [q0, q1]

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

→[q0] [q0, q1] [q1]

*[q1] ϕ [q0, q1]

*[q0, q1] [q0, q1] [q0, q1]

The transition table for the constructed DFA will be:

The Transition diagram will be:

Even we can change the name of the states of DFA.


Suppose

1. A = [q0]
2. B = [q1]
3. C = [q0, q1]

With these new names the DFA will be as follows:

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 2: Draw the transition table for all pair of states.

Step 3: Now split the transition table into two tables T1 and T2. T1 contains all final
states, and T2 contains non-final states.

Step 4: Find similar rows from T1 such that:

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 6: Repeat step 3 and step 4 for table T2 also.

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 4: Set 1 has no similar rows so set 1 will be the same.

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

Step 6: Now combine set 1 and set 2 as:


State 0 1

→q0 q1 q3

q1 q0 q3

*q3 q3 q3

Now it is the transition table of minimized DFA.

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 zero or more occurrence of x. It can generate {e, x,


xx, xxx, xxxx, .....}

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.

2.1. Formal Definition


Formally, a regular language can be defined as the collection of all
strings that are recognized by a finite automata (FA).
An FA is a 5-tuple , where:

1. stands for a finite number of states


2. stands for a finite alphabet, representing the input symbols
3. stands for the transition function which maps to
4. stands for the initial state. It is one of the elements of
5. stands for the set of final states. F is also a subset of .

FAs and regular expressions specify patterns or rules that define a


language, such as sequences of characters that must or must not
appear in the strings. The words in a regular language must follow the
rules specified by the finite automaton or regular expression to be part
of the language.

2.2. Examples of Regular Languages


Some common examples of regular languages include:

• Binary strings that represent even numbers


• Set of strings that contain exactly two a‘s
• The set of all binary numbers that are divisible by 3
• The set of all strings that contain the substring “01”
(Closure Properties) Operations on Regular Language
The various operations on regular language are:

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.

1. L* = Zero or more occurrence of language L.

You might also like