0% found this document useful (0 votes)
2 views

Module 3

The document outlines the syllabus for a course on the Theory of Computation, focusing on topics such as regular expressions, finite automata, and their interrelations. It details operations on regular languages, methods for converting finite automata to regular expressions, and the construction of finite automata from regular grammars. Additionally, it discusses the Pumping Lemma for proving the irregularity of languages and provides examples and definitions related to regular grammars and automata.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 3

The document outlines the syllabus for a course on the Theory of Computation, focusing on topics such as regular expressions, finite automata, and their interrelations. It details operations on regular languages, methods for converting finite automata to regular expressions, and the construction of finite automata from regular grammars. Additionally, it discusses the Pumping Lemma for proving the irregularity of languages and provides examples and definitions related to regular grammars and automata.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

BCSE304L-THEORY OF

COMPUTATION

1 BCSE304L- Theory of Computation


Syllabus

2 BCSE304L- Theory of Computation


Syllabus

3 BCSE304L- Theory of Computation


Syllabus

4 BCSE304L- Theory of Computation


Module 3
 Regular Expression and Finite Automata
 Finite automata are used to recognize
patterns. It takes the string of symbols as
input and transforms its state accordingly.
When the required symbol is found, then the
transition occurs.
 Regular Expressions are the expressions
that describe the language accepted by
Finite Automata. It is the most efficient way to
represent any language.
 The languages accepted by some regular
expressions are referred to as Regular
5 Languages Dr. R.V. Aswiga , Assistant Professor (Sr.), School
of Computer Science and Engineering, VIT
 Regular expressions are used to check and match the
combinations of characters in the strings.
 Find the operation that can be applied/matched on a string
pattern.
 Let Σ be an alphabet that denotes the input set.
The regular expression over Σ can be defined as follows:
 1.) Φ is a regular expression that denotes the empty set.
 2.) ε is a regular expression and denotes the set {ε}, called
a null string.
 3.) If ‘a’ and ‘b’ are the regular expressions that denote the
language L1 and L2, respectively, then:-
a.) a+b is equal to L1 U L2 union.
b.) ab is equal to the L1L2 concatenation.
c.) a* is equal to L1* closure.
6 Dr. R.V. Aswiga , Assistant Professor (Sr.), School
of Computer Science and Engineering, VIT
Operations On Regular Language

 The various operations on the regular language are:


 1.) Union: If ‘a’ and ‘b’ are the regular expressions that
denote the language L1 and L2, respectively, their union L1 U
L2 is also a Regular Language.
 Example : a + b is equal to L1 U L2 union.

 2.) Intersection: If ‘a’ and ‘b’ are the regular expressions


that denote the language L1 and L2, respectively, their
intersection is also a Regular Language.
 L1 ⋂ L2 = {ab | a is in L1 and b is in L2}
 Example : ab is equal to the L1L2 concatenation.

 3.) Kleene closure: If R is a regular language, its Kleene


closure * will also be a Regular Language.
 R* = Zero or more occurrences of language R.

7 Dr. R.V. Aswiga , Assistant Professor (Sr.),


School of Computer Science and
FA to RE
 There are two methods to convert FA to the
regular expression:
 1. State Elimination Method:
 2. Arden’s Theorem:

8 Dr. R.V. Aswiga , Assistant Professor (


Sr.), School of Computer Science and
1. State Elimination Method:

 Steps:
 Add a new start state and final state add an €-transition
between the new and the existing states
 One by one, bypass and eliminate the non initial and the final
states in the transition diagram
 A state is bypassed or eliminated by combining each
outgoing edge with the incoming edge
 The label of the resultant edge is the concatenation of the
outgoing and incoming edge alphabets along with loop edges
if there is one.
 When 2 or more parallel edges are going in the same
direction from one state, unify them by union of (+)
their labels
 Finally only one edge is left from initial to final state.
 The label on that edge is the regular expression

9 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Example Formats

10 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
(Contd.,)

Dr. R.V. Aswiga , Assistant Professor (Sr.), School


11 of Computer Science and Engineering, VIT
Chennai.
Convert the following NFA TO RE
Using State Elimination Method

12 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
13 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of
Computer Science and Engineering, VIT Chennai.
Ardens Theorem

14 Dr. R.V. Aswiga , Assistant Professor (Sr.),


School of Computer Science and
15 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of
Computer Science and Engineering, VIT Chennai.
RE to FA
 Thompson’s Construction Method
(NFA with Epsilon)

 Construct a NFA for RE 01+1*0

16 Dr. R.V. Aswiga , Assistant Professor (


Sr.), School of Computer Science and
Construct a NFA for RE (00+11)*01

17 Dr. R.V. Aswiga , Assistant Professor (Sr.),


School of Computer Science and
RE to FA (NFA Informal Technique)
 Construct an FA equivalent to the RE
(0+1)*(00+11)(11)*

18 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
RE to FA (Informal Technique)
 Construct an FA equivalent to the RE
(0+1)*(00+11)(11)*
 Constructing in a straight forward manner
starting with only one initial and final state
 Then eliminate concatenations by adding
states step by step
 Finally remove the epsilon transition.

19 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
Final Result

20 Dr. R.V. Aswiga , Assistant Professor (Sr.),


School of Computer Science and Engineering,
RE to DFA
 Construct DFA for RE=(0+1)*00(0+1)*

 L={ 00,000,100,000,001,0000,0001,…}

21 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Construct DFA for RE=(0+1)*011

Dr. R.V. Aswiga , Assistant Professor (Sr.),


22
School of Computer Science and
Pattern Matching and FA
 Construct an automata for the pattern bada

 Text : abdababadad

 Steps:

 Draw the FA for the given pattern


 b a d a
q3 q
q0 q1 q2 4

23 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
Transition Table with Prefix
Matching
a b d
0 1
1 2
2 3
3 4
4

a b d
0 0 1 0
1 2 1 0
2 0 1 3
3 4 1 0
4 0 1 0

24 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
25 Dr. R.V. Aswiga , Assistant Professor (
Sr.), School of Computer Science and
Types of Grammar in Automata

 There are several types of grammars in automata


theory, each with different properties and
capabilities.
 Regular Grammar
 A regular grammar is a type of formal grammar
that generates a regular language.
 A regular language is a language that can be
recognized by a finite automata or a regular
expression.
 Regular grammars are the simplest type of formal
grammars and are commonly used in computer
science and programming language theory.

26 Dr. R.V. Aswiga , Assistant Professor (


Sr.), School of Computer Science and
Rules
 In a regular grammar, all the production rules
have only one non-terminal symbol on the
left-hand side and a terminal symbol or a
non-terminal symbol followed by a
terminal symbol on the right-hand side.

 The terminal symbols represent the basic


building blocks of the language. (Small
Letters)
 The non-terminal symbols represent a group
of one or more strings of symbols. (Capital
letters)
27 Dr. R.V. Aswiga , Assistant Professor (Sr.),
School of Computer Science and Engineering,
The formal definition of a regular
grammar
 A regular grammar is a quadruple G = (V, Σ, P, S)

where
 V is a finite set of non-terminal symbols,
 Σ is a finite set of terminal symbols,
 P is a set of production rules of the form A → α, where A is a non-
terminal symbol and α is a string of symbols in (V ∪ Σ) *, and
 S is the start symbol.

The production rules in a regular grammar must be in one of


the following forms:
 A → aB, where A and B are non-terminals, and a is a terminal
symbol
 A → a, where A is a non-terminal, and a is a terminal symbol
 S → ε, where S is the start symbol, and ε represents the empty
string
Dr. R.V. Aswiga , Assistant Professor (Sr.), School
28
of Computer Science and Engineering, VIT
Example
 Consider the regular grammar G = ({S, A, B}, {0,
1}, P, S)
P : production rules
 S → 0A
 A → 1B
 B → 0A | 1B | ε
 In this grammar, S is the start symbol, and the non-
terminal symbols are S, A, and B. The terminal
symbols are 0 and 1. The production rules follow the
above format, where the left-hand side is a non-
terminal symbol, and the right-hand side is a string
of symbols consisting of non-terminals and
terminals.
29 Dr. R.V. Aswiga , Assistant Professor (Sr.),
School of Computer Science and Engineering,
Example

Given
 S → 0A
 A → 1B
 B → 0A | 1B | ε

For example, the string "010101" is in L(G) because it


can be generated by the grammar as follows:
 S → 0A
 A → 1B
 B → 0A
 A → 1B
 B → 0A
 A → 1B
 B → ε

30 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Summary
 Regular grammar is a simple formal grammar
that generates a regular language,
 Regular Language is a language that can be
recognized by a finite automata or a regular
expression.
 The production rules in a regular grammar
have a specific format, and the grammar can
be used to generate strings in the regular
language by applying the production rules
starting from the start symbol.

31 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
The above grammar can be of two
forms
 Right Linear Regular Grammar
 Left Linear Regular Grammar

Linear Grammar
 When the right side of the Grammar part has only one
terminal then it's linear else non linear.
Left linear grammar
 In a left-regular grammar (also called left-linear
grammar), the rules are of the form as given below −
 L → Ma
 If the non terminal is at the left most in the RHS

Right Linear Regular Grammar


 L → aM
 If the non terminal is at the right most in the RHS

32 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
Regular Grammar To FA
 Construct a finite-automata that accepts the language
generated by a given grammar G.

Let G = (V, T, P, S) be a regular grammar, where


 V = {A0, A1, A2} T = {0, 1}
 S is the start symbol of the grammar {A }.
0
 P is the set of production rules

Production rules defined as:


 A -> 0A
0 1

 A0 -> 1A2
 A1 -> 0A2
 A2 -> 0
33 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of Computer
Science and Engineering, VIT Chennai.
Regular Grammar to FA Solution
 Let M = ( Q, ∑, δ, q0, F ) be a finite-
automata that accepts L (G), where
 Q = {A0, A1, A2, Af}
 ∑ = {0, 1}
 A0 is the initial state F = {Af}

34 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
35 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of
Computer Science and Engineering, VIT Chennai.
36 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of
Computer Science and Engineering, VIT Chennai.
Dr. R.V. Aswiga , Assistant Professor (Sr.),
37
School of Computer Science and Engineering,
Example 2

38 Dr. R.V. Aswiga , Assistant Professor (Sr.), School


of Computer Science and Engineering, VIT
Pumping lemma for regular
languages
 Pumping Lemma is used as a proof for
irregularity of a language.

 Pumping lemma is to be applied to show that


certain languages are not regular.

 The fact that all sufficiently long strings in


such a language have a substring that can be
repeated arbitrarily many times, usually used
to prove that certain languages are not
regular

39 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Method
 It gives a method for pumping (generating)
many substrings from a given string.

 In other words, we say it provides means to


break a given long input string into several
substrings.

 Gives necessary condition(s) to prove a set of


strings is not regular.

40 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Theorem
 Assume that the given set is regular and accepted by FA
that have n states

 Choose a string w such that |w| >= n

 Using Pumping Lemma write w = xyiz for i>=0, which


means y not is not empty, such that |xy|<=n
(string y is ‘pumped’, i.e., if y is inserted any number of
times, the resultant string still remains in L. )

 For a suitable integer i, such that w = xyiz not in the


language. We have achieved the contradiction.

 Conclude L is not regular


41 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of
Computer Science and Engineering, VIT Chennai.
What are the closure properties of
Regular languages ?
Union
Intersection
concatenation
Kleene closure
Complement
Union
 If L1 and If L2 are two regular languages, their
union L1 U L2 will also be regular.
Example
 L1 = {an | n > O} and L2 = {bn | n > O}
 L3 = L1 U L2 = {an U bn | n > O} is also regular.

42 Dr. R.V. Aswiga , Assistant Professor (Sr.), School of


Computer Science and Engineering, VIT Chennai.
Intersection
 If L1 and If L2 are two regular languages, their intersection L1 ∩ L2
will also be regular.
 L1= {am bn | n > 0 and m > O} and
 L2= {am bn U bn am | n > 0 and m > O}
 L3 = L1 ∩ L2 = {am bn | n > 0 and m > O} are also regular.
Concatenation
 If L1 and If L2 are two regular languages, their concatenation L1.L2
will also be regular.
 L1 = {an | n > 0} and L2 = {bn | n > O}
 L3 = L1.L2 = {am . bn | m > 0 and n > O} is also regular.
Kleene Closure
 If L1 is a regular language, its Kleene closure L1* will also be regular.
 L1 = (a U b )
 L1* = (a U b)*
Complement
 If L(G) is a 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.
43 Dr. R.V. Aswiga , Assistant Professor (Sr.),
School of Computer Science and Engineering,

You might also like