Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 35

Automata and Complexity Theory

Introduction
Mr. Dereje B (Msc)

4/23/23 Automata and Complexity Theory -1-


Theory of Computation
It is a branch of computer science that deals with how efficiently a
problem can be solved on a model of computation, using an algorithm.
• Theory of computation is divided into 3 fields:
1. Automata Theory and Formal Languages
2. Computability Theory
3. Complexity Theory
• The goal is to ascertain the power and limits of computation.
• In order to study these aspects, it is necessary to define precisely what
constitutes a model of computation as well as what constitutes a
computational problem.
• This is the purpose of automata theory.
• The computational models are automata, while the computational
problems are formulated as formal languages.
4/23/23 Automata and Complexity Theory -2-
cont…
1. Automata Theory and Formal Languages
• It deals with the definition and properties of various
mathematical model of computation. • Examples:
i. Finite Automata(FA)
ii. Context Free Grammar (CFG)
iii. Turing Machine (TM)
2. Computability Theory
• It deals with what can/cannot be computed by the model.
3. Complexity Theory
• It groups the computable problems based on their hardness.
Main purpose of Theory of Computation
• Develop formal mathematical model of computation that
reflect real world computers.
4/23/23 Automata and Complexity Theory -3-
Alphabets and Strings
1. Symbol
• Symbol(often also called character) is the smallest building
block, which can be any alphabet, letter, or picture.
• Example
• a, b, c, …, z
• 0,1,…, 9
• +,*, #, … special characters
2. Alphabet
• An alphabet is a finite, non-empty set of symbols.
• It is denoted by ∑.
• Examples: ∑ = {0,1} set of binary alphabets.

4/23/23 Automata and Complexity Theory -4-


cont…
Examples: ∑ = {a, b, c, …, z} set of all lowercase letters.
∑ = {A, B, C, …Z} is an alphabet of uppercase letters.
∑ = {+, #, &,$, …} set of all special characters
3. String or Word
• It is a finite collection of symbols from the alphabet.
• The string is denoted by w.
• Example: w = 01110 is string from binary alphabet ∑ =
{0,1}
w = aabbaacaa is string from alphabet ∑ = {a, b, c}
Symbol Alphabet String/Word

4/23/23 Automata and Complexity Theory -5-


cont…
4. Empty String
• Empty string is a string with zero occurrences of symbol(no
symbol)..
• It is denoted by ' ε ' → no symbol { }
5. Length of String
• It is the number of symbols in the string.
• It is denoted by |w|.
• Example 1: w = 010110101 from binary alphabet ∑ = {0,1}
Length of the string |w| =9.
Example 2: w = 010
Length of Sting |w| = 3

4/23/23 Automata and Complexity Theory -6-


count…
6. Concatenation of String : joining of 2 or more strings.
• Let x = a1, a2, a3, …, an
y= b1,b2,b3, …, bn
• Concatenation of string xy = a1, a2, a3, …, anb1,b2,b3, …,
bn
• Example: S = ababa and T = cdcddc
Concatenation of string ST = ababacdcddc
7. Power of an Alphabet
• If ' ∑ ' is an alphabet, we can express set of all string of
certain length from
that alphabet by using exponential notation.
• It is denoted by ∑k is the set of strings of length k.

4/23/23 Automata and Complexity Theory -7-


count…
• Example: ∑ = {0,1} has 2 symbols.
(i) ∑1 = {0,1} therefore 2pow1 = 2 where k = 1
(ii) ∑2 = {00,01, 10,11} therefore 2 pow2 = 4 where k = 2
(ii) ∑3 = {000, 001, 010, 011, 100, 101, 110, 111 } therefore
2pow3 = 8 where k = 3
8. Language:
A language is a collection of appropriate string.
A language which is formed over Σ can be Finite or Infinite.
Example: 1
L1 = {Set of string of length 2} = {aa, bb, ba, bb} Finite
Sprache
L2 = {Set of all strings starts with 'a'} = {a, aa, aaa, abb,
abbb, ababb} Infinite Language
4/23/23 Automata and Complexity Theory -8-
Automata
Theory of automata is a theoretical branch of computer science and
mathematical.
• It is the study of abstract machines and the computation problems that
can be solved using these machines.
• The abstract machine is called the automata.
• The main motivation behind developing the automata theory was to
develop methods to describe and analyze the dynamic behavior of
discrete systems.
• This automaton consists of states and transitions.
• The State is represented by circles, and the Transitions is represented
by arrows.
• Automata is the kind of machine which takes some string as input and
this input goes through a finite number of states and may enter in the
final state.

4/23/23 Automata and Complexity Theory -9-


Finite Automata(FA)
• Finite automata are used to recognize designs.
• It takes the string of symbol as input and changes its state accordingly.
• When the desired symbol is found, then the transition occurs.
• At the time of transition, the automata can either move to the next state
or stay in the same state.
• Finite automata have two states:
• Accept state or
• Reject state.
• When the input string is processed successfully, and the automata
reached its final state, then it will accept, otherwise it will reject the
input.

4/23/23 Automata and Complexity Theory -10-


Cont…
• Finite automata can be represented by:
• Graphical (Transition diagrams)
• Tabular (transition tables)
• Mathematical (Transition function or Mapping function)

4/23/23 Automata and Complexity Theory -11-


Formal Definition of FA
A finite automaton is a collection of 5-tuples (Q, ∑, δ, q0, F),where:
• Q is finite set of states
• ∑ is finite set of the input alphabets
• q0 ϵ Q is start state also called initial state
• F is accept state or final state
• δ: Q x ∑ → Q is transition function

4/23/23 Automata and Complexity Theory -12-


Transition Diagrams
Transition diagram is a directed graph associated with vertices of
the graph corresponds to the state of finite automata.

{0, 1} are inputs


q0 initial state
q1 intermediate state
q2 is final state

4/23/23 Automata and Complexity Theory -13-


Transition Table
 Transition Table is basically a tabular representation, of
the transition function that takes two arguments( a state
and a symbol ) and returns a value (next state).
 Transition Table
 Rows corresponds to states,
 Columns corresponds to input symbols
 Entries corresponds to next state
 The start state is marked with an arrow (→)
 Accept state are marked with a star(*)
 q1 intermediate state
 q2 is final state.

4/23/23 Automata and Complexity Theory -14-


Cont…

4/23/23 Automata and Complexity Theory -15-


Transition Function
• The mapping function or transition function denoted by δ.
 Two parameters are passed to this transition function
1. current state
2. input symbols
• Transition function always returns a state which can be
called as next state.
Qx∑→Q
δ(current state, current input symbol) = next state
• Example: δ(q0, a) = q1
δ(q0, 1) = q1

4/23/23 Automata and Complexity Theory -16-


Types of Automata

4/23/23 Automata and Complexity Theory -17-


Deterministic Finite Automata (DFA)
Finite automata is called deterministic finite automata if the
machine read an input string one symbol at a time.
• Deterministic refers to the uniqueness of the computation.
• In DFA, there is only one path for specific input symbol from
current state to the next state.
• DFA does not accept the null move.
• DFA cannot change the state without any input character.
• DFA can contains multiple final state.
• DFA is used in lexical analysis in compiler.

4/23/23 Automata and Complexity Theory -18-


Formal Definition of DFA
A DFA is a collection of 5 tuples (same as FA)
• Q is finite set of states
• ∑ is finite set of input symbols
• q0 is initial state
• F is final state
• δ is transition function
 Transition function can be defined as δ : Q x ∑ → Q
 The state is represented by vertices.
 The arc labeled with an input character show the transition
 The initial state is marked with an arrow.
 The final state is denoted by a double circle.

4/23/23 Automata and Complexity Theory -19-


Acceptance of a Language
• A language acceptance is defined by “if a string w is
accepted by a machine m”
If it is reaching the final state F by taking the string w.
Not accepted if not reaching the final state.

4/23/23 Automata and Complexity Theory -20-


cont…
Note : states depends on the length of the string.
• Example 1: Let DFA be Q = {q0, q1,q2}, ∑ = {0, 1}, initial
state ={q0}and final state ={q2.}
• So, Construct DFA for the below table.

4/23/23 Automata and Complexity Theory -21-


Non Deterministic Finite Automata (DFA)
The finite automata are called NFA when there exist many
paths for specific input from the current state to the next state.
• It is easy to construct an NFA than DFA for a given regular
language.
• Every NFA is not DFA, but each NFA can be translated into
DFA.
• NFA is defined in the same way as DFA but with the
following two exceptions:
1. it contains multiple next states, and
2. it contains ε transition.

4/23/23 Automata and Complexity Theory -22-


cont…
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.

4/23/23 Automata and Complexity Theory -23-


Formal definition of NFA
NFA also has five tuples same as DFA, but with different
transition function, as
shown follows:
δ: Q x ∑ →2Q
where,
• Q finite set of States
• ∑ finite set of input symbol
• q0 initial state
• F final state
• δ transition function

4/23/23 Automata and Complexity Theory -24-


Graphical Representation of an NFA
An NFA can be represented by digraphs called state diagram.
In which:
 The state is represented by vertices.
 The arc labeled with an input character show the transitions.
 The initial state is marked with an arrow.
 The final state is denoted by the double circle.

4/23/23 Automata and Complexity Theory -25-


cont…

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.

4/23/23 Automata and Complexity Theory -26-


NFA with ε
 ε is empty symbol( no character to accept)
 Regular NFA with 5 tuples {Q, ∑, q0, F, δ}
where δ : Q x ∑ → 2Q
• ε -NFA with 5 tuples {Q, ∑, q0, F, δ}
where δ : Q x ∑ U ε → 2Q

4/23/23 Automata and Complexity Theory -27-


Difference between DFA and NFA

4/23/23 Automata and Complexity Theory -28-


Minimization of DFA
•The minimization of DFA means reducing the number of states from a
given FA.
• Step1: Remove all the states that are unreachable from initial state
via any set of transition of DFA.
Step2: Draw the transition table for all pair of states.
Step3: Now split the transition table into two tables T1 and T2.
 T1 contains all final states T2 contains non
final states
•Step4: Find similar rows from T1, such that:
δ(q, a) =p
δ(r, a) =p
Find the two states which have same value of a
and b and remove one of them.

4/23/23 Automata and Complexity Theory -29-


cont…
Step5: Repeat step 3 until we find no similar rows available in T1
Step6: Repeat step 3 and step 4 for table T2 also.
Step7: Now combine the reduced T1 and T2 tables.
 i.e.. the final transition table of minimized DFA.
•Example 1: Minimization of DFA

4/23/23 Automata and Complexity Theory -30-


cont…
Step1: Remove q2 and q4 in FA because they are unreachable states

4/23/23 Automata and Complexity Theory -31-


cont…

4/23/23 Automata and Complexity Theory -32-


cont…

4/23/23 Automata and Complexity Theory -33-


Application of Finite Automata
Finite Automata (FA) used:
1.For the designing of lexical analysis of a compiler.
2.For recognizing the pattern using regular expressions.
3.For the designing of the combination and sequential circuits
using Mealy and Moore Machines.
4.Used in text editors.
5.For the implementation of spell checkers.

4/23/23 Automata and Complexity Theory -34-


The
4/23/23
End
Automata and Complexity Theory -35-

You might also like