0% found this document useful (0 votes)
79 views18 pages

Unit 1 - Finite Automata

AutometA

Uploaded by

khushiashok3105
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
79 views18 pages

Unit 1 - Finite Automata

AutometA

Uploaded by

khushiashok3105
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 18

UNIT 1 FINITE AUTOMATA

Contents:-

Introduction- Basic Mathematical Notation and techniques- Finite State systems – Basic Definitions – Finite
Automaton – DFA & NDFA – Finite Automaton with €- moves – Regular Languages- Regular Expression –
Equivalence of NFA and DFA

Introduction:-

Automata theory is a combination of computer science and mathematics. This theory provides the fundamental
knowledge that is required to developed or design the new programming languages, for compiler construction,
searching string, pattern matching, computer security and artificial intelligence.

Theory of Computation is a combination of computer Science and mathematics. It shows how efficiently we can
solve any problem using model of computation or algorithm. Automata theory is one of the branch of theoretical
computer science. It is a study of abstract machine and computational problem. A machine takes input and after
processing produces output.

Finite automata is a simple machine to recognize the pattern.

Finite State machine is a mathematical or computational model that can be used to represent and control
execution flow of that system. It can be used in many fields like mathematics, artificial intelligence, natural
language processing etc. It has a limited number of state and one state of the machine is active at a time. It
means machine moves from one state to another to perform specific task or action.

Finite state machine has a limited memory, so when any state moves from one state to another state with
specified input, it provides the output and holds it for a specified time. Finite State machine is also called as
automata theory. It is a logic of simple machine.

A real-life example of finite state machine is a traffic light. It has three state Red, Green & Yellow. It changes
the state at a specified time, Red to green, green to yellow and yellow to red. Another example of automata
theory is video game controller. When the user presses a button, the system performs the actions based on it.

The application of Finite Automata is:

Speech recognition and processing

Pattern matching

Compilers Construction

Symbol: It is user defined entity.

Example: digit, letters etc.

Alphabet (Σ):

It is finite set of symbols that are denoted by Greek letter sigma (Σ).

For example

Σ ={ a, b, c} is the set of alphabet and ‘a’ ,’b’ and ‘c’ is the symbol.
Σ = {0,1,2,3} is the set of alphabet and ‘0’ ,’1’ , ‘2’ and ‘3’ is the symbol.

String:

A string is a finite sequence of symbol from the alphabet. For example, 11001 is a string from the binary
alphabet Σ = {0,1}.

A string which has no symbol is called empty string and is denoted by Є.

The length of a string is number of symbol in string and its length is denoted by |w|. for example, |1011| = 4 and
|Є| = 0.

Prefix & Suffix of Strings:

Prefix – a prefix of a string is any number of leading symbol of that string.

Proper Prefix – a prefix of a string other than the string itself is called proper prefix of a string.

For example: x = “INDIA”

Prefix = {Є, “I”,” IN”, “IND”,” INDI”, ”INDIA”}

Proper Prefix = {Є, “I”,”IN”, “IND”, INDI”}

Suffix – a suffix of a string is any number of trailing symbols of that string.

Proper Suffix – a suffix other than the string itself is called proper suffix.

For example x = “INDIA”

Suffix = {Є , “A” ,”IA” , “DIA” ,”NDIA”,”INDIA”}

Proper Suffix = {Є , “A” ,”IA” , “DIA” ,”NDIA”}

Formal Language:

It is a set of finite-length of string from alphabet. In this grammar is used to generate words.

Or

Formal language L over an alphabet Σ is a subset of Σ*, that is, a set of word over that alphabet.

For example

Describe the language of all strings that start with a over alphabet Σ ={a}

L = {a,aa,aaa,aaa,…………}

Describe the language of all strings that start with 0 over alphabet Σ ={0,1}
L = {0,001,00,011,01,010…………..}

Operations on Languages:

Concatenation - If L1 and L2 are two languages then concatenation is denoted by L1L2(First string followed by
second).

For example - Let L1={a} & L2 ={b} then find L1L2.

L1L2 = {ab}

Let L1={ab, b} & L2 ={a, ba} then find L1L2 ?

ab{a, ba} * b{a, ba}

L1L2 ={aba, abba, ba, bba}

Kleene Closure /Kleene star –

It is concatenation of zero or more elements with itself. It is denoted by Σ*.

Σ*=Σ0 U Σ1 U Σ2.....

For example - Σ={a} then

Σ* = Σ0U Σ1 U Σ2 …………..

= {ε} U {a} U {a}{a} U {a}{a}{a} …………

Σ*={ε,a, aa, aaa, aaaa,….}

Positive Closure / Kleene Plus –

It is concatenation of one or more elements with itself. It is denoted by Σ+.

Σ+ = Σ* - Σ0

Σ+ = Σ1 U Σ2.....

For example-

Σ={a} then

Σ + = Σ1 U Σ2 …………..

= {a} U {a}{a} U {a}{a}{a} …………

Σ + ={a, aa, aaa, aaaa,….}

Repetitions

It L is a language then Li means repeat I times.

For example- L = {a}, L0 = {ɛ}, L1 = {a}, L2 = {a}{a} = {aa}, L3 = {a}{a}{a} = {aaa}

Deterministic finite Automata


Finite Automata -

A finite automaton (FA) is a machine that recognizes pattern or language. It has a fixed memory. It accepts input
symbol and change its state based on current state. If the input string is successfully processed till the end of the
string and automata reaches till final or accepting state, input is accepted; otherwise rejected.

Determinstic Finite
Automata(DFA)

Finite Automata without NonDeterminstic Finite


output Automata(DFA)

NonDeterminstic Finite
Finite Automata Automata(DFA) with ε

Moore Machine
Finite Automata with
output
Mealy Machine

Fig. Finite Automata

Finite Automaton can be classified into two types −

Deterministic Finite Automaton (DFA)

Non-deterministic Finite Automaton (NDFA / NFA)

Deterministic finite Automaton

Finite means the number of possible state and number of symbol in the alphabet are finite. Automaton means the
changes of state based on input.

The term “deterministic” means for each input there is one and only one transition state to which the automaton
can move from its current state.

Fig. Transition Sate

A (deterministic) FA is 5-tuple

(Q, Σ, δ , q0, F) where:

• Q is a finite set of states;

• Σ is a finite input alphabet;


• q0 is an initial state;

• F is Final or accept states; and

• δ is a transition function mapping. δ: Q × Σ → Q.

Terminology of DFA

State- The vertices represent the state.

Transition - The edges labelled with an input alphabet shows the transitions.

Final State - The final state is indicated by double circles. It is also called as terminal state or accepting state.

Transition Table – A table which represents the set of state in a row and the input alphabet in the columns.

Self-Loop – when any edge shows the transition to itself for any input alphabet.

Construction of DFA Procedure

Construct a DFA for L =” ab”.

In this example DFA accepts only “ab” string and rejects all other strings. It always starts with an initial state q 0.
q0 is called as initial state and takes input “a” and moves to q1. The edge or arc drawn between q0 to q1 with input a
is called transition and transition mapping δ (q0, a) = q1. After processing the first input, it again starts with q1
state and reads next symbol i.e., “b”, and moves from q1 to q2. This continues till we reach the final state.

M = {Q, Σ, δ, q0, F}
Transition Table

δ a b

q0 q1 qerror

q1 qerror q2

q2 qerror qerror

qerror qerror qerror


Construction of Transition table:

It is a tabular representation of the transition function. It has two arguments, state (Q) and a symbol (Σ ) and
output returns to the “next state”.

• Rows correspond to states & Columns correspond to input symbols of alphabet.

• Entries correspond to next states.

• The start state is marked with an arrow & final or accepted states is marked with a star (*).

DFA as language recognizer –

Deterministic finite automata has 5 tuple (Q,Σ,δ,q0,F). It always starts from initial state and reads the symbol and
moves from one state to another as given by transition function. After reading the entire input it reaches to a
final state. The Final or accepting state either accepts or rejects the string. When the string is accepted by the
automata or machine it is said to be language recognizer by the automaton.
Formal Definition: The language accepted by FA is denoted as L(M) is the set{x| (q0, x} is in F}

The language recognized or accepted by deterministic finite automata is called regular language and regular
language is language which is accepted by finite automata.

A grammar generates the language and finite automata recognizes it.

Generate recognize
Grammar Language Automata
Example

L = (ab) where Σ = {a,b}

This accepts only “ab” and reject all other string.

Start q0 a q1 b q2 (Final
State) = Accept
Start q0 b qerror (Non-Final
State) = Reject

DFA as pattern recognizer –

The language accepted by the finite automata is called regular language. Regular language described by
algebraic expression is called regular expression.

A regular expression is a set of string according to syntax rules. This expression is used by text editor, search
engine and for pattern matching purpose. DFA accepts the regular expression so it is also called pattern
recognizer.

For example: -

L = Construct a DFA which accept the string ending with 00 over Σ ={0, 1}.

RE = (0+1)* 00

Solution

DFA accept the language only L = {00, 100 , 10100, 0100, 000, . . . . . . }

M = (Q, Σ, δ , q0, F)
Transition Table

δ 0 1

q0 q1 q0

q1 q2 q0

q2 q2 q0

Difference between DFA and NFA :

DFA NFA

DFA stands for Deterministic Finite Automata. NFA stands for Nondeterministic Finite Automata.

For each symbolic representation of the alphabet, No need to specify how does the NFA react according
there is only one state transition in DFA. to some symbol.

DFA cannot use Empty String transition. NFA can use Empty String transition.

In NFA, each pair of state and input symbol can have


In DFA, the next possible state is distinctly set.
many possible next states.

DFA is more difficult to construct. NFA is easier to construct.

All DFA are NFA. Not all NFA are DFA.

DFA requires more space. NFA requires less space then DFA.

Dead configuration is not allowed. Dead configuration is allowed.

eg: if we give input as 0 on q0 state so we must eg: if we give input as 0 on q0 state so we can give
give 1 as input to q0 as self loop. next input 1 on q1 which will go to next state.

δ: QxΣ -> Q i.e. next possible state belongs to Q. δ: Qx(Σ U ε) -> 2^Q i.e. next possible state belongs to
DFA NFA

power set of Q.

Backtracking is allowed in DFA. Backtracking is not always possible in NFA.

Conversion of Regular expression to DFA is Conversion of Regular expression to NFA is simpler


difficult. compared to DFA.

Epsilon move is not allowed in DFA Epsilon move is allowed in NFA

DFA allows only one move for single input There can be choice (more than one move) for single
alphabet. input alphabet.

Nondeterministic finite automaton (NFA)

Definition –

The term nondeterministic refers to each input symbol that returns set of zero or more state or any finite
automata and allows zero or more transition for each input symbol. DFA is a special case of NFA.

A (Nondeterministic) FA is 5-tuple

(Q, Σ, δ , q0, F) where:

• Q is a finite set of states;

• Σ is a finite input alphabet;

• q0 is an initial state;

• F is Final or accept states; and

• δ is a transition function mapping. δ: Q × Σ → 2Q (i.e. power set of Q).

Example1

Construct NFA for the language which starts with ab over Σ = {a, b}.

Solution –

M = (Q, Σ, δ, q0, F) where:


NFA with ε- transitions

The NFA is allowed to make a transition without receiving an input symbol, i.e., transition with ε means the
empty string.

Definition –

The finite automata with ε move is the automata in which the state can be change without receiving any input
symbol.

The meaning of ε move indicate NULL transition from one state to another.

NFA with ∈ move: If any FA contains ε transaction or move, the finite automata is called NFA with ∈ move.

A Non-Deterministic Finite Automata with ε transitions is a 5-tuple

(Q, Σ, qo, δ, F) where –

Q is a finite set (of states)

Σ is a finite alphabet of symbols

qo is the initial state

F ⊆ Q is the set of accepting states

δ is a function from Q x (Σ ∪ {ε}) to 2Q (transition function)

Examples 1

Construct NFA with ε which can accept language consisting any no. of 0’s and any no. of 1’s.

Solution –

NFA accept the language


L = {ε, 0 , 00,000, ……….. 01, 011, 11, 111, 000111, ………..}

NFA- ε = (Q, Σ, qo, δ, F)

Q = {q0, q1}, Σ = { ε , 0,1}

q0 = q0 , F = q1

Transition Table

δ 0 1 ε

q0 q0 ф ф

q1 ф q1 ф

Examples 2

Construct NFA with ε which can accept language consisting any no. of 0’s followed by any no. of 1’s followed
by any no. of 2’s .

Solution –

NFA- ε accept the language

L = {ε, 0 , 00,000, ………..1, 01, 011, 11, 111, 000111, … , 012, 2,22, 02, 00122, ……..}

NFA- ε = (Q, Σ, qo, δ, F)

Q = {q0, q1, q2 }, Σ = { ε , 0,1}

q0 = q0 , F = q2

Transition Table

δ 0 1 2 ε

q0 q0 ф ф ф

q1 ф q1 ф ф

q2 ф ф q2 ф
Regular Expressions (RE): Definition & Example

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.

The languages accepted by some regular expression are referred to as Regular languages.

A regular expression can also be described as a sequence of pattern that defines a string.
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, a* means zero or more occurrence of x. It can generate {e, a, aa, aaa, aaaa…}

In a regular expression, a+ means one or more occurrence of x. It can generate {a, aa, aaa, aaaa…}

Applications of Regular Expression:

There are various application of regular expression. They are given below.

1. Compiler uses regular expressions for representing various rules and regulation regarding tokens like
variables, constants, keywords, and various used defined entities.

2. Various operating system uses regular expressions in commands of command line interface Example wild
characters,? Used in DOS operating system Meta characters like *, ? , . , [] used in UNIX operating system.

3. Database management software uses regular expressions for finding out user defined entities from readymade
entities

4. Spread sheet software also uses regular expression for filtering records among the database

5. Some utility software also uses regular expression in there code like LEX Which accept regular expression as
input and produce equivalent C program as output.

Regular expression (Defination)


Regular expressions are used to denote regular languages. They can represent regular languages and operations
on them briefly.
The set of regular expressions over an alphabet is defined recursively as below. Any element of that set is
a regular expression.
Basis Clause: , and a are regular expressions corresponding to languages 𝛟 , { } and {a}, respectively,
where a is an element of .
Inductive Clause: If r and s are regular expressions corresponding to languages Lr and Ls , then ( r +
s ) , ( rs ) and ( r*) are regular expressions corresponding to languages Lr Ls , LrLs and Lr* , respectively.

External Clause: Nothing is a regular expression unless it is obtained from the above two clauses.

Some RE Examples

Regular Expressions Regular Set

(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }

(0*10*) L = {1, 01, 10, 010, 0010, …}


(0 + ε)(1 + ε) L = {ε, 0, 1, 01}

(a+b)* Set of strings of a’s and b’s of any length including the null string. So L = { ε, a, b, aa ,
ab , bb , ba, aaa…….}

(a+b)*abb Set of strings of a’s and b’s ending with the string abb. So L = {abb, aabb, babb, aaabb,
ababb , …………..}

(11)* Set consisting of even number of 1’s including empty string, So L= {ε, 11, 1111,
111111 , ……….}

(aa)*(bb)*b Set of strings consisting of even number of a’s followed by odd number of b’s , so L =
{b, aab, aabbb, aabbbbb, aaaab, aaaabbb, …………..}

(aa + ab + ba + bb)* String of a’s and b’s of even length can be obtained by concatenating any combination
of the strings aa, ab, ba and bb including null, so L = {aa, ab, ba, bb, aaab, aaba...}

2.2 Regular Expressions Identities

Given R, P, L, Q as regular expressions, the following identities hold −

∅* = ε

ε* = ε

RR* = R*R

R*R* = R*

(R*)* = R*

(PQ)*P =P(QP)*

(a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*

R + ∅ = ∅ + R = R (The identity for union)

R ε = ε R = R (The identity for concatenation)

∅ L = L ∅ = ∅ (The annihilator for concatenation)

R + R = R (Idempotent law)

L (M + N) = LM + LN (Left distributive law)

(M + N) L = ML + NL (Right distributive law)


ε + RR* = ε + R*R = R*

2.3 Regular language-Definition and Examples.

The set of regular languages over an alphabet is defined recursively as below. Any language belonging to
this set is a regular language over .

Definition of Set of Regular Languages:

Basis Clause: 𝛟, { } and {a} for any symbol a € are regular languages.
Inductive Clause: If Lr and Ls are regular languages, then Lr Ls , LrLs and Lr* are regular languages.

External Clause: Nothing is a regular language unless it is obtained from the above two clauses.

For example, let = {a, b}. Then since {a} and {b} are regular languages, {a, b} ( = {a} {b} ) and {ab}
( = {a}{b} ) are regular languages. Also since {a} is regular, {a} * is a regular language which is the set of
*
strings consisting of a's such as , a, aa, aaa, aaaa etc. Note also that , which is the set of strings
consisting of a's and b's, is a regular language because {a, b} is regular.

The regular languages are those languages that can be constructed from the three set of operations viz.,

Union

Intersaction

Concatenation

Kleene closure

Complement

Closure Properties of Regular Languages


Union : If L1 and If L2 are two regular languages, their union L1 ∪ L2 will also be regular. For example, L1
= {an | n ≥ 0} and L2 = {b n | n ≥ 0}
L3 = L1 ∪ L2 = {an ∪ bn | n ≥ 0} is also regular.

Intersection : If L1 and If L2 are two regular languages, their intersection L1 ∩ L2 will also be regular. For
example,
L1= {am bn | n ≥ 0 and m ≥ 0} and L2= {a m bn ∪ bn am | n ≥ 0 and m ≥ 0}
L3 = L1 ∩ L2 = {am bn | n ≥ 0 and m ≥ 0} is also regular.

Concatenation : If L1 and If L2 are two regular languages, their concatenation L1.L2 will also be regular.
For example,
L1 = {an | n ≥ 0} and L2 = {b n | n ≥ 0}
L3 = L1.L2 = {am . bn | m ≥ 0 and n ≥ 0} is also regular.

Kleene Closure : If L1 is a regular language, its Kleene closure L1* will also be regular. For example,
L1 = (a ∪ b)
L1* = (a ∪ b)*

Complement : If L(G) is regular language, its complement L’(G) will also be regular. Complement of a
language can be found by subtracting strings which are in L(G) from all possible strings. For example,
L(G) = {an | n > 3}
L’(G) = {an | n <= 3}

Example 1

Write the regular expression for the language accepting all combinations of a's, over the set ∑ = {a}

Solution:

All combinations of a's means a may be zero, single, double and so on. If a is appearing zero times, that means a
null string. That is we expect the set of {ε, a, aa, aaa, ....}. So we give a regular expression for this as:

R = a*

That is Kleen closure of a.

Example 2

Write the regular expression for the language accepting all combinations of a's except the null string, over the
set ∑ = {a}

Solution:

The regular expression has to be built for the language

L = {a, aa, aaa, ....}

This set indicates that there is no null string. So we can denote regular expression as:

R = a+

Example 3

Write the regular expression for the language accepting all the string containing any number of a's and b's.

Solution:

The regular expression will be:

r.e. = (a + b)*

This will give the set as L = {ε, a, aa, b, bb, ab, ba, aba, bab, .....}, any combination of a and b.

The (a + b)* shows any combination with a and b even a null string.

Example 4

Describe the language denoted by following regular expression

r.e. = (b* (aaa)* b*)*

Solution:
The language can be predicted from the regular expression by finding the meaning of it. We will first split the
regular expression as:

r.e. = (any combination of b's) (aaa)* (any combination of b's)

L = {The language consists of the string in which a's appear triples, there is no restriction on the number of b's}

Example 5

Write the regular expression for the language L over ∑ = {0, 1} such that all the string do not contain the
substring 01.

Solution:

The Language is as follows:

L = {ε, 0, 1, 00, 11, 10, 100, .....}

The regular expression for the above language is as follows:

R = (1* 0*)

Example 6

Write the regular expression for the language containing the string over {0, 1} in which there are at least two
occurrences of 1's between any two occurrences of 1's between any two occurrences of 0's.

Solution: At least two 1's between two occurrences of 0's can be denoted by (0111*0)*.

Similarly, if there is no occurrence of 0's, then any number of 1's are also allowed. Hence the r.e. for required
language is:

R = (1 + (0111*0))*

Example 7

Write the regular expression for the language containing the string in which every 0 is immediately followed by
11.

Solution:

The regular expectation will be:

R = (011 + 1)*

Example 8

Which one of the following languages over the alphabet {0,1} is described by the regular expression?
(0+1)*0(0+1)*0(0+1)*
(A) The set of all strings containing the substring 00.
(B) The set of all strings containing at most two 0’s.
(C) The set of all strings containing at least two 0’s.
(D) The set of all strings that begin and end with either 0 or 1.
Solution : Option A says that it must have substring 00. But 10101 is also a part of language but it does not
contain 00 as substring. So it is not correct option.
Option B says that it can have maximum two 0’s but 00000 is also a part of language. So it is not correct
option.
Option C says that it must contain atleast two 0. In regular expression, two 0 are present. So this is correct
option.
Option D says that it contains all strings that begin and end with either 0 or 1. But it can generate strings
which start with 0 and end with 1 or vice versa as well. So it is not correct.

Example 9

Which of the following languages is generated by given grammar?


S -> aS | bS | ∊
(A) {an bm | n,m ≥ 0}
(B) {w ∈ {a,b}* | w has equal number of a’s and b’s}
(C) {an | n ≥ 0} ∪ {bn | n ≥ 0} ∪ {an bn | n ≥ 0}
(D) {a,b}*

Solution : Option (A) says that it will have 0 or more a followed by 0 or more b. But S -> bS => baS => ba is
also a part of language. So (A) is not correct.
Option (B) says that it will have equal no. of a’s and b’s. But But S -> bS => b is also a part of language. So (B)
is not correct.
Option (C) says either it will have 0 or more a’s or 0 or more b’s or a’s followed by b’s. But as shown in
option (A), ba is also part of language. So (C) is not correct.
Option (D) says it can have any number of a’s and any numbers of b’s in any order. So (D) is correct.

Example 10:

The regular expression 0*(10*)* denotes the same set as


(A) (1*0)*1*
(B) 0 + (0 + 10)*
(C) (0 + 1)* 10(0 + 1)*
(D) none of these

Solution : Two regular expressions are equivalent if languages generated by them are same.
Option (A) can generate all strings generated by 0*(10*)*. So they are equivalent.
Option (B) string null can not generated by given languages but 0*(10*)* can. So they are not equivalent.
Option (C) will have 10 as substring but 0*(10*)* may or may not. So they are not equivalent.
Equivalence of NFA and DFA-

You might also like