Automata

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

Arba Minch University

Arba Minch Institute of Technology


Faculty of Computing & Software
Engineering

AUTOMATA & COMPLEXITY


THEORY
CHAPTER 1
INTRODUCTION

Introduction - Alphabets and Strings –


Language –Grammars – Automata – Finite
Automata
INTRODUCTION
WHAT IS AUTOMATA THEORY?

• Automata theory: is the study of abstract machines(theoretical


model of real computer) and automata, as well as the computational
problems that can be solved by using them.
• The automaton: is an abstract computing device(It is an abstract model
of digital computer).
• Abstract devices are model of real world computation.
• Why do we need abstract models?
Computability( can we solve a problem by using machine?) vs.
Complexity(time taken to find a solution)
ALPHABETS A N D
STRINGS
An alphabet is defined as a non empty finite set of symbols. The alphabet is normally
denoted by Σ , whose elements are called symbols.

Example 1: Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} —set of decimal digits.

Example 2: Σ = {0, 1} —set of binary digits.

Example 3: Σ = {a, b, c, . . ., x, y, z} —set of lower-case letters in English.

Example 4: Σ = {0, 1,a,b,#,*,{,},&}

Non-example: N = {0, 1, 2, 3, . . .} — set of all non-negative whole numbers is not an alphabet,


because it is infinite.
ALPHABETS AND STRINGS

Strings or Word: is a finite sequence, possibly empty, of symbols drawn


from some alphabet Σ.

• Sequence of concatenated symbols of Σ.

• Combination of the individual symbols of set.

Example 1 : Σ={ 0, 1 } 0110, 11, 001 are three strings over the binary alphabet Σ.

Example 2 : Σ= { a, b, c }. aab, abcb, b, cc are four strings over the alphabet Σ.

Given any alphabet Σ, the shortest string that can be formed from Σ is the empty
string, which we will write as ε. i.e., The length of empty string is | ε |=0

The set of all possible strings over an alphabet Σ is written Σ*.


ALPHABETS AND STRINGS

Functions on Strings / String operations


Length : The number of symbols in a string w is called its length, denoted by |w|.
Example 1 : Σ={0,1} string= | 011 | = 3, |11| = 2, | b | = 1, | ε |=0
Example 2 : Σ ={a, b,c,…,z}
S1=boy, |S1|=3 S2=software, |S2|=8 S3=abbcd, |S3|=5
• For any symbol c and string s, we define the function #c(s) to be the number of times that the
symbol c occurs in s. So, for example, #a(abbaaa) = 4.
Concatenation : The concatenation of two strings s and t, written s || t or simply st, is the
string formed by appending t to s. For example, if x = good and y = bye, then xy = goodbye.
So |xy| = |x| + |y|.
ALPHABETS AND STRINGS

Functions on Strings / String operations


Powers of Strings : For each string w and each natural number i, the string
wi is defined as:
w0 = ε, wi+1 = wiw
Example: a3 = aaa, (bye)2 = byebye, a0b3 = bbb
String Reversal : For each string w, the reverse of w, which we will write wR,
is defined as:
For any string w= a1a2a3...an, the reversal of the string is wR= anan-1... a3a2a1
Example: w=abcd, wR =dcba if |w| = 0 then wR = w = ε

Palindrome: is one of property of string which string can be read same from
left to right as well as from right from left. For example: MadaM
ALPHABETS A N D
STRINGS
Powers of Alphabets
 We write Σk (for some integer k) to denote the set of strings of length k with symbols from Σ. In
other words,
 Σk= { w | w is a string over Σ and | w | = k}. Hence, for any alphabet, Σ 0 denotes the set of all strings
of length zero. That is, Σ0= {ε}.
 Example 1: For the binary alphabet Σ={ 0,1 } we have the following.
Σ0={ε}. the set of all string of length 0,
Σ1= {0, 1},the set of all string of length 1,
Σ2= {00, 01,10,11},the set of all string of length 2,
Σ3= {000, 001, 010, 011, 100, 101, 110, 111}, the set of all string of length 3
 The set of all strings over an alphabet is Σ denoted by Σ*. That is
Σ*=Σ0U Σ1U Σ2U Σ3U…. ΣnU…
Σ*={ε, 0, 1, 00, 01,1, 000, 001, 010, 011, 111,…}
ALPHABETS A N D
STRINGS
Relations on Strings
Substring: A string s is a substring of a string t iff s occurs contiguously as part of t.
Example: aaa is a substring of aaabbbaaa | aaaaaa is not a substring of aaabbbaaa
Proper substring: A string s is a proper substring of a string t iff s is a substring of t and s ≠ t.
Every string is a substring (although not a proper substring) of itself. The empty string, ε, is a
substring of every string.
Prefix: A string s is a prefix of t iff Ǝx ϵ Σ* (t = sx). Proper prefix: A string s is a proper prefix
of a string t iff s is a prefix of t and s ≠ t.
Every string is a prefix (although not a proper prefix) of itself. The empty string, ε, is a prefix of
every string. For example, the prefixes of abba are: ε, a, ab, abb, abba.
Suffix: A string s is a suffix of t iff Ǝx ϵ Σ* (t = xs). Proper suffix: A string s is a proper suffix
of a string t iff s is a suffix of t and s ≠ t.
Every string is a suffix (although not a proper suffix) of itself. The empty string, ε, is a suffix of every
string. For example, the suffixes of abba are: ε, a, ba, bba, abba.
LANGUAGE
Language is a (finite or infinite) set of strings over a finite alphabet Σ.
Let Σ = {a, b}. Σ * = {ε, a, b, aa, ab, ba, bb, aaa, aab, …}.
Some examples of languages over Σ are:
Ø, {ε}, {a, b}, {ε, a, aa, aaa, aaaa, aaaaa}, {ε, a, aa, aaa, aaaa, aaaaa, …}
Therefore, a language L is any subset of Σ*
 The languages we consider for our discussion is an abstraction of natural languages. Our focus here
is on formal languages that need precise and formal definitions.
 Formal language is a language designed for use in situations in which natural language is
unsuitable, as for example in mathematics, logic, or computer programming.
 Formal Language(language) consists of strings whose symbols are taken from alphabet and are well
formed according to specific set of rules.
 A formal language is the set of all strings permitted by the rules of formation. Based upon the set of
rules we can say that, given string is part of language or not.
LANGUAGE
Example: Σ1={a,b,c,….z): the set of small case letter in English.
Σ2={0,1,2,3…,9}: the set of decimal digits
Σ3 ={0,1}
L1 : The set of all string over Σ1, that contains the substring “at”. L1 ={cat, hat, mat, eat, ate, gate,….}

L2 : The set of all string over Σ2 that are divisible by 7. L2={7,14,21,…..}

L3 : The set of all string that is in the form S#S where s is any string over Σ 1. L3 ={a#a, b#b, ab#ab,...}

L4 : the set of all string starting with 1 over Σ3. L4 : {1,10,11,110,111,…..}

L5 : Set of all string with length 2 over Σ3. Try it?


L6 : Set of all strings starting with 0 and ending in 1 over Σ 3.
L7 :{W| W=anbn, n ≥ 1}
GRAMMAR
 In the context of natural languages, the grammar of a language is a set of rules which are used to
construct/validate sentences of the language.
 Now we draw the attention to look into the general features of the grammars (of natural languages)
to formalize the notion in the present context which facilitate for better understanding of formal
languages.
 Consider the English sentence:-
The students study automata theory.
 In order to observe that the sentence is grammatically correct, one may attribute certain rules of the
English grammar to the sentence and validate it.
 For instance, the Article ⇒ the followed by the Noun ⇒ students form a Noun-phrase and
similarly the Noun ⇒ automata theory form a Noun-phrase. Further, Verb ⇒ study.
Derivation of an English Sentence According
to English Grammar GRAMMAR
• Sentence: The students study automata
theory.
• Now, choose the Sentential form “Subject Verb Object”
of the English grammar.
 As Subject or Object can be a Noun-phrase by
plugging in the above words one may conclude that
the given sentence is a grammatically correct
English sentence.
GRAMMAR
 Definition: A grammar is a quadruple G = (N, Σ, P, S) where
1. N is a finite set of non-terminals,
2. Σ is a finite set of terminals,
3. S ∈ N is the start symbol, and
4. P is a finite subset of N × V∗ called the set of production rules. Here, V = N ∪ Σ.
 Example: consider the Grammar G=({S,A,B}, {a,b},{S→AB, A→a, B→b}, S)
 Nonterminal(N)={S,A,B}, terminals (Σ)={a,b}, Production rule(P)={S→AB, A→a, B→b},
Start symbol(S)= S.
GRAMMAR
 The set of all strings that can be derived from a grammar is said to be the language generated from
that Grammar
 Example. Let P = {S → ab, S → bb, S → aba, S → aab} with Σ = {a, b} and N = {S}. Then G =
(N, Σ, P, S) is a context-free grammar.

 Since left hand side of each production rule is the start symbol S and their right hand sides are
terminal strings, every derivation in G is of length one. In fact, we precisely have the following
derivation in G.
1. S ⇒ ab 2. S ⇒ bb 3. S ⇒ aba 4. S ⇒ aab
Hence, the language generated by G,
L(G) = {ab, bb, aba, aab}.
Notation: A → α1, A → α2 can be written as A → α1 | α2.
Grammar Types on the basis of production rule:
1. Type 0 - Unrestricted Grammar or Parse-Structure grammar
2. Type 1 - Context Sensitive Grammar
3. Type 2 - Context Free Grammar
4. Type 3 - Regular Grammar

<S>  <NP> <VP>


Meaning of this single arrow () is left side is rewritten as right side

α => β
Meaning of the double arrow ( => ) deriving β from the α in one step

α’ β’
Meaning of the double arrow star ( ) β’ obtained from the α’ in zero or most steps
Example:
S The man ate the fruit
- is called reflexive transitive closure of =>
FORMAL LANGUAGE
AUTOMATA
Automata: A algorithm or program that automatically recognizes if a particular string belongs to
the language or not, by checking the grammar of the string.
 An automata is an abstract computing device (or machine).
 An automaton is a, construct that possesses all the indispensable features of a digital computer. It
accepts the input, produces output, may have some temporary memory, and can make decisions
in transforming the input into the output.
AUTOMATA
Every Automaton fulfills the three basic requirements
 Every automaton consists of some essential features as in real computers. It has a mechanism for
reading input. The input is assumed to be a sequence of symbols over a given alphabet and is
placed on an input tape(or written on an input file). The simpler automata can only read the input
one symbol at a time from left to right but not change. Powerful versions can both read (from left
to right or right to left) and change the input.
 The automaton can produce output of some form. If the output in response to an input string is
binary (say, accept or reject), then it is called an accepter. If it produces an output sequence in
response to an input sequence, then it is called a transducer(or automaton with output).
 The automaton may have a temporary storage, consisting of an unlimited number of cells, each
capable of holding a symbol from an alphabet ( which may be different from the input alphabet).
The automaton can both read and change the contents of the storage cells in the temporary storage.
The accusing capability of this storage varies depending on the type of the storage.
AUTOMATA
FINITE AUTOMATA (FA)
Finite Automata (FA)
 Simplest form of an automation
 It consists of only input tape and finite control unit not temporary storage
 Tape has a read only head
 Input tape is divided in to cells and each
cell can hold one symbol
 It will read the left to right, it can read
one symbol at a time
 While reading if it found no symbol then it stop the operation of automata
 Control unit determines the state of the automata and control the movement of the head on the
input tape
 It will accepts the regular languages
FINITE AUTOMATA (FA)
FA Definition
FA is a collection of 5-tuples (Q, Σ, δ,q0,F)
 Q – finite set of states
 Σ – finite input alphabet
 δ – transition function or mapping
 q0 – initial state, q0 ϵ Q
 F – set of final state

Types of FA
 Deterministic Finite Automata (DFA)
 Nondeterministic Finite Automata (NFA)
FINITE AUTOMATA (FA)
Transition diagram:
Transition diagram is defined as collection of:
 Finite set of states K
 Finite set of symbols ∑
 Non empty set S of K, S is called start state
 Set of F of K, F is called final state
 Transition function

S --- Represents the states 𝑆 0 --- Start symbol

S  Final State
FINITE AUTOMATA (FA)
Examples 1:

Example 2:
FINITE AUTOMATA (FA)
Transition Table (Transition Matrix):
Tabular representation of the finite automata. For transition function is used
Example:
FINITE AUTOMATA (FA)
Transition Function:
Transition or Mapping function is denoted by δ. Two parameters are passed to this transition
function: one is current state and other is input symbol. The transition function returns a state which
can be called as next state.
For example
= δ (, a)
current state
a input
 next state
FINITE AUTOMATA (FA)
Solved Problems for FA:
Example: Design a FA which accepts the only input 101 over the input set Z = { 0, 1}.
Problem statement is mentioned only input 101 will be accepted. So we can simply show the transition
diagram for the input.

Example: Design a FA which checks whether the given binary number is even.
Even  any binary number ends with 0
Ex: 2  0010, 4  0100, 6  0110, 8  1000
Odd  any binary number ends with 1
Ex: 1  0001, 3  0011, 5  0101, 7  0111
FINITE AUTOMATA (FA)
While designing FA, assume one start state, One state ending with
0 and another one ends with 1. we want to check whether the
given binary number is even or odd so fix the final state for 0 value.
Let take 2 sample inputs one odd and one even:
Case 1: For even number Case 2: For odd number
1000 => 1000 1011 => 1 011
=> 10 00 => 10 11
=> 100 0 => 101 1
=> 1000 => 1011
In case1: now at the end of input we are at final or accept state so its even number
In case2: now at the end of input we are at S1 state not in final state so its not even (odd) number
FINITE AUTOMATA (FA)
1. Design a FA which accepts only those strings which starts with 1 and ends with 0

2. Design FA which accepts even number of 0’s and even number of 1’s

3. Consider the given transition table and Find the language accepted by the finite automata
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )

The finite automata is called Deterministic Finite Automata if there is only one path for a specific
input from current state to next state.
From the given example transition diagram
From state for input ‘a’ there is only one path going to state .
Definition:
DFAdefinition is same as the finite automata
DFA is a five tuple notation denoted as: A = ( Q, ∑, δ, , F)
Q  finite set of states
∑  finite set of input symbols
δ transition function
 start state
F  final state
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )

Example: Design a DFA which accepts string with even number 0’s and ends with single 1
over = { 0, 1 }. Give Transition table
Let take the sample strings:
1, 001, 00001, 0101, 001
will accepts the odd numbers of 0’s
will accepts the even number of 0’s
It should be followed by binary 1. so
will be final state.

Example: Design a DFA which accepts all the strings not having more than two a’s over = {a, b}.
From the problem statement DFA will accepts that strings contain maximum two a’s. if we try to accept
3rd a’s it will not lead as to final state.
D E T E R M I N I S T I C F I N I T E A U T O M ATA
( D FA )

Transition table

Example 2.5: Design a DFA for accepting all strings of


L = { | m ≥ 0 and n ≥ 1 }
Step 1: m=0 and n=1 => 1
Step 2: m=1 and n=1 => 01
Step 3: m=1 and n=2 => 011
Final transition diagram is
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

• NFA is exactly reverse of DFA


• Many paths for a specific input from current state to next state

• From the transition diagram


• Current state
• Specific input ‘a’
• Multi path: , 
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

Definition:
NFA formally defined as a collection of five tuple: A = ( Q, ∑, δ, , F)
Q  finite set of states
∑  finite set of input symbols
δ transition function
 start state (initial)
F  set of final state

Difference between DFA and NFA:


• In DFA for a given input we reach to the deterministic or unique state
• In NFA it lead to more than one state for a given input
• DFA is a subset of NFA
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

Example: Construct the NFA for the given transition table

Example: Draw the transition diagram for NFA over { a, b } containing substring aabb.
Definition of Substring: Any string of consecutive symbols in some string is said to be a substring of
that string.
For example w = abbab u = bba
String ‘u’ is a substring of string ‘w’
D I F F E R E N C E B E T W E E N ( N FA ) A N D D FA

• DFA and NFA are both types of finite automata, which are theoretical
models used to describe and analyze the behavior of formal languages.
While they share some similarities, there are key differences between
the two:
• Deterministic Finite Automaton (DFA):
• Deterministic: In a DFA, for each input symbol, there is exactly one
transition from each state. This means that the next state is uniquely
determined by the current state and the input symbol.
• Single initial state: A DFA has a single initial state from which the
computation begins.
• No ε-transitions: DFA does not have ε-transitions, which are transitions
that can be taken without consuming any input symbol.
• No multiple outgoing transitions: From each state in a DFA, there can be
at most one transition for each input symbol. In other words, there are
no multiple outgoing transitions labeled with the same symbol.
D I F F E R E N C E B E T W E E N ( N FA ) A N D D FA

• Non-deterministic Finite Automaton (NFA):


• Non-deterministic: In an NFA, for each input symbol, there can be zero, one, or
multiple transitions from each state. This means that the next state is not
uniquely determined by the current state and the input symbol.
• May have multiple initial states: An NFA can have multiple initial states, and the
computation can start from any of these states.
• May have ε-transitions: NFA can have ε-transitions, allowing it to transition to
the next state without consuming any input symbol.
• Multiple outgoing transitions: From each state in an NFA, there can be multiple
transitions for the same input symbol, or even no transition at all.
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

Step1: For only Substring – aabb

Step2: Values in front of substring: aaabb, baabb, abaabb, baaabb

Step3: Values behind substring: aaabba, baabbb, abaabbab, baaabbba


N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

Example: Draw transition diagram for NFA over {0, 1} containing substring 01 and 10
This example is similar to previous Example :
Substring 01

Substring 10 1 0
Combine both:

=>
N O N D E T E R M I N I S T I C F I N I T E A U T O M ATA
( N FA )

1. Draw the transition diagram and table for NFA in which


double 1 is followed by double 0 over { 0, 1 }.

2. Construct NFA accepting binary strings with two


consecutive 0’s. consider input set ∑ = { 0, 1 }

3. Design NFA accepting all strings end with 01, over ∑ =


{0, 1}
N FA E QU I VA L E N C E OF D FA & N FA

Significance of NFA:

- Basically computers are deterministic machines

- DFA will produce the predictable output for the certain input

- Constructing deterministic machine is very difficult

- NFA easy to construct

- NFA can easily convert to DFA

- This conversion mechanism is majorly used in compiler

- NFA serves as a bridge between input given and DFA constructed


N FA E QU I VA L E N C E OF D FA & N FA

NFA with ε Transition:


In order to move from one state to another state without having any
symbol of input set ∑.

With out any input symbol from q state to p state transition is happened by ε
moves

The above automata will accepts only the L = { | m, n, p ≥ 0}


For the sample input ‘01’. First self transition happened for the state for the input
‘0’. For the second input symbol there is no transition path so with ε transition
automata reaching the state from . After that self transition happened for the
input ‘1’ in state . At last, automata reaching the final state with ε transition from
the state
N FA E QU I VA L E N C E OF D FA & N FA

Definition of NFA with ε:


language L is accepted by NFA with ε. M = ( Q, ∑, δ, , F )
where
Q  finite set of states
∑  finite set of input symbols
δ transition function Q x {∑ U ε} to
 start state
F  final state
N FA E QU I VA L E N C E OF D FA & N FA

Definition of ε – closure:
set of all states which are reachable from particular one state on ε –
transition.
Example : Find the ε – closure for the following NFA with ε

ε – closure() = {, , } means self state + ε – reachable states

ε – closure() = {, } is a self state + is a state obtained from with ε


input.

ε – closure() = {}
N FA E QU I VA L E N C E OF D FA & N FA

Conversions and Equivalence:


NFA with ε can be converted to NFA without ε and this NFA without ε can be
converted to DFA. Here we are going to discuss these conversions and will find
them equivalent to each others

Conversion from NFA with ε to NFA without ε:


Step1: Find out all the ε transition from each state from Q. (find ε – closure for
each states from Q)
Step2: Find δ’ transition (means ε – closure on δ with ε moves)
Step3: repeat step2 for each input symbol and for each state
Step4: From the resultant transition table can construct the NFA without ε
N FA E QU I VA L E N C E OF D FA & N FA

Example: Convert the given NFA with ε to NFA without ε


Step1: Find ε – closure for each states:

Step2: Find δ’ transition for each state on each input symbol:


N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA

Example: convert the following NFA with ε to NFA without ε

Step1: Find ε – closure for each states:

Step2: Find δ’ transition for each state on each input symbol:


N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA

Example: Construct the DFA for the given NFA transition table.
From the given transition table:
left side and states are
available. In right side {, }
new state is available. For this
new state, we have to find the transition for new state {, } on each input {0, 1}
N FA E QU I VA L E N C E OF D FA & N FA
N FA E QU I VA L E N C E OF D FA & N FA

Example: Convert the given NFA to DFA


From the given table: In left side
,, , are the states. In right side
{, } new state available. So we have
to find the transition for the new {, }
state on each input {0, 1}.
N FA E QU I VA L E N C E OF D FA & N FA

New state {, ,} is created in the previous computation, so again find the


transition for the new state {, ,} on each input.
δ‘([, ,], 0) = δ(,0) U δ(,0) U δ(,0) = {, } U { U { = {, ,, }
Here also new state {, ,, } is generated
δ‘([, ,], 1) = δ(,1) U δ(,1) U δ(,1) = { U { U { = {, ,}
Here also new state {, , } is generated. Again find the transition for the above
two new states on each input.
δ‘([, ,, ], 0) = δ(,0) U δ(,0) U δ(,0) U δ(,0)
= {, } U { U { U φ = {, ,, }
δ‘([, ,, ], 1) = δ(,1) U δ(,1) U δ(,1) U δ(,1)
= { U { U { U { = {, ,, }
No more new states so we can finish the computation
N FA E QU I VA L E N C E OF D FA & N FA

In the given NFA q is a final state so in DFA where ever exits that state become
3
final state of DFA.
N FA E QU I VA L E N C E OF D FA & N FA

Try yourself
1. Convert the given NFA to DFA

End of Chapter - 01
PROBLEMS

Solved Problems
1. Design a FA which accepts only those strings which starts with 1 and
ends with 0

2. Design FA which accepts even number of 0’s and even number of 1’s
3. Consider the given transition table and Find the language accepted
by the finite automata
Draw the transition diagram for the given transition table

It will accepts the even no of 1’s and even no of 0’s. for example: strings
are: 0011, 1010. 1001, 111100, etc.,
4. Draw the transition diagram and table for NFA in which double 1 is
followed by double 0 over { 0, 1 }.
Finite Automata for double 1

Automata for double 1 is followed by 0

Prefix and suffix on the previous automata

Sample input string: 1100, 11100, 01100


101100, 01100, 11000, 11001, 110000
110010
5. Construct NFA accepting binary strings with two consecutive 0’s.
consider input set ∑ = { 0, 1 }
Automata for consecutive two 0’s:

Prefix and suffix input values on consecutive 0’s

Sample input string: 00, 000, 100, 0000, 0100, 000, 001, 0001, 0010
6. Design NFA accepting all strings end with 01, over ∑ = {0, 1}
Automata for 01

String end with 01. So automata with prefix input values

Sample input: 01, 001, 101, 0001, 0101, 1001, 1101

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy