SlideShare a Scribd company logo
1 of 44
UNIT II
REGULAR EXPRESSIONS AND
LANGUAGES
Mrs.D.Jena Catherine Bel,
Assistant Professor, CSE,
Velammal Engineering College
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
1
UNIT II
REGULAR EXPRESSIONS AND LANGUAGES
Regular Expressions – FA and Regular Expressions – Proving
Languages not to be regular – Closure Properties of Regular
Languages – Equivalence and Minimization of Automata.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
2
Models
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
3
Models
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
4
Regular Expressions
• The algebraic notations describes exactly the same language
as finite automata
• The language described by regular expression or a finite
automata is known as regular languages
• The regular expression operators are union, concatenation
and closure
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
5
Let Regular expression R, then Regular language L(R) defined as
follows:
• L(Φ)= Φ
• L()={}
Let Alphabet ∑={a,b}
• If R=a then L(a)={a}
• If R=b then L(b)={b}
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
6
Example
RE Representation RL
a+b L(a)U L(b) -> {a} U {b} {a,b}
ab+bc L(ab)U L(bc) -> {ab} U {bc} {ab,bc}
(a+b).c L(a+b).L(c) -> {a,b}.{c} {ac,bc}
a(0+1)b L(a).L(0+1).L(b)
{a}.{0,1}.{b}
{a0b,a1b}
(a+b)(0+1) L(a+b).L(0+1) ->{a,b}.{0,1} {a0,a1,b0,b1}
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
7
Operators of Regular expression
• Union
• L = {01 , 10}
• M = {ε ,00, 11}
• L U M = {ε ,00, 11,01,10}
• Concatenation
• L = {01 , 10}
• M = {ε ,00, 11}
• L M = {01, 10, 0100, 1000, 0111, 1011}
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
8
• Closure
• L = {01 , 10}
• L * = {ε, 01, 10, 0101,010101,0110,1001,…….}
• L+ = {01, 10, 0101,010101,0110,1001,…….}
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
9
Example
• Give the regular expression for set of all strings starting with
0.
• Give the regular expression for set of all strings ending with 0.
•
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
10
Example
• Give the regular expression for set of all strings ending with
00.
• Give the regular expression for set of all strings starting with 0
and ending with 1
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
11
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
12
Thompson's construction /
McNaughton-Yamada-Thompson
algorithm
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
13
Basis
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
14
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
15
(0+1)*1(0+1)
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
16
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
17
FA to RE - Methods
1.Using Rij formula
(Transitive closure method)
2. State Elimination Method
3. Arden’s Method
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
18
Rij Method
• DFA states are defined as {1,2,3,4,. . . n}
• k={0,1,2,3,4,. . . n}
• Rij Formula : 𝐑𝐢𝐣
(𝐤)
= 𝐑𝐢𝐣
(𝐤−𝟏)
+
𝐑𝐢𝐤
𝐤−𝟏
𝐑𝐤𝐤
𝐤−𝟏 ∗
𝐑𝐤𝐣
(𝐤−𝟏)
• i is the initial state (1) , j is the final state ꞓ F
• The required RE is sum of union of 𝑹𝒊𝒋
(𝒏)
such that j is the
accepting state
𝑹𝒊𝒋
(𝒏)
is computed by,
𝑹𝒊𝒋
(𝒌=𝟎)
, 𝑹𝒊𝒋
(𝒌=𝟏)
. . . 𝑹𝒊𝒋
(𝒌=𝒏)
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
19
Properties of Regular Expression
• Commutative:
• R+S = S+R
• Associative:
• (R+S)+T = R+(S+T)
• (RS)T = R(ST)
• Identity:
• R+Φ = R
•  R = R  = R
• Annihilator:
• ΦR = RΦ = Φ
◦ Distributive:
◦ R(S+T) = RS + RT
◦ (R+S)T = RT+ST
◦ Idempotent: R+ R = R
◦ Involving Kleene
closures:
◦ (R*)* = R*
◦ Φ* = 
◦ * = 
◦ R+ =RR*
◦ R? =  +R
◦  +R* = R*
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
20
DFA to RE Ex-1
• DFA: Start state =1 Final state=3
• Total Number of nodes (n) = 3 & k={0,1,2,3}
• The required regular expression is
1 2 3
a b
𝑹𝒊𝒋
(𝒏)
𝑹𝟏𝟑
(𝟑)
𝐑𝐢𝐣
(𝐤)
= 𝐑𝐢𝐣
(𝐤−𝟏)
+ 𝐑𝐢𝐤
𝐤−𝟏
𝐑𝐤𝐤
𝐤−𝟏 ∗
𝐑𝐤𝐣
(𝐤−𝟏)
i.e i=1 , j=3
,k=3
𝐑𝟏𝟑
(𝟑)
= 𝐑𝟏𝟑
(𝟐)
+ 𝐑𝟏𝟑
𝟐
𝐑𝟑𝟑
𝟐 ∗
𝐑𝟑𝟑
(𝟐)
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
21
Computation of K=0
1 2 3
a b
𝑹𝟏𝟏
(𝟎)
𝑹𝟏𝟑
(𝟎)
𝑹𝟏𝟐
(𝟎)
𝑹𝟐𝟏
(𝟎)
𝑹𝟐𝟐
(𝟎)
𝑹𝟐𝟑
(𝟎)
𝑹𝟑𝟏
(𝟎)
𝑹𝟑𝟐
(𝟎)
𝑹𝟑𝟑
(𝟎)
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
22
Computation of K=0 - cont.
1 2 3
a b
𝑹𝟏𝟏
(𝟎)
= 
𝑹𝟏𝟑
(𝟎)
= Φ
𝑹𝟏𝟐
(𝟎)
= 𝒂
𝑹𝟐𝟏
(𝟎)
= Φ
𝑹𝟐𝟐
(𝟎)
= 
𝑹𝟐𝟑
(𝟎)
= 𝒃
𝑹𝟑𝟏
(𝟎)
= Φ
𝑹𝟑𝟐
(𝟎)
= Φ
𝑹𝟑𝟑
(𝟎)
= 
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
23
Computation of K=1
𝑹𝟏𝟏
(𝟏)
= 𝑹𝟏𝟏
(𝟎)
+ 𝑹𝟏𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟏
𝟎
= +  ()∗  = 
𝑹𝟏𝟑
(𝟏)
= 𝑹𝟏𝟑
(𝟎)
+ 𝑹𝟏𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟑
𝟎
=Φ+  ()∗Φ=Φ
𝑹𝟏𝟐
(𝟏)
= 𝑹𝟏𝟐
(𝟎)
+ 𝑹𝟏𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟐
𝟎
= 𝒂+  ()∗ 𝐚 = a+a=a
𝑹𝟐𝟏
(𝟏)
= 𝑹𝟐𝟏
(𝟎)
+ 𝑹𝟐𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟏
𝟎
=Φ+ Φ()∗  =Φ
𝑹𝟐𝟑
(𝟏)
= 𝑹𝟐𝟑
(𝟎)
+ 𝑹𝟐𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟑
𝟎
=b+Φ= 𝒃
𝑹𝟐𝟐
(𝟏)
= 𝑹𝟐𝟐
(𝟎)
+ 𝑹𝟐𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟐
𝟎
=  +Φ= 
𝑹𝟑𝟑
(𝟏)
= 𝑹𝟑𝟑
(𝟎)
+ 𝑹𝟑𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟑
𝟎
=  +Φ= 
𝑹𝟑𝟐
(𝟏)
= 𝑹𝟑𝟐
(𝟎)
+ 𝑹𝟑𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟑
𝟎
=Φ+Φ=Φ
𝑹𝟑𝟏
(𝟏)
= 𝑹𝟑𝟏
(𝟎)
+ 𝑹𝟑𝟏
𝟎
(𝑹𝟏𝟏
𝟎
)
∗
𝑹𝟏𝟏
𝟎
=Φ+ Φ =Φ
a+a = {a,a} = {a} so that
RE is a
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
24
Computation of K=2 and
K=3
𝑹𝟏𝟑
(𝟐)
= 𝑹𝟏𝟑
(𝟏)
+ 𝑹𝟏𝟐
𝟏
(𝑹𝟐𝟐
𝟏
)
∗
𝑹𝟐𝟑
𝟏
=Φ+ a()∗b=ab
𝑹𝟑𝟑
(𝟐)
= 𝑹𝟑𝟑
(𝟏)
+ 𝑹𝟑𝟐
𝟏
(𝑹𝟐𝟐
𝟏
)
∗
𝑹𝟐𝟑
𝟏
=  +Φ= 
𝑹𝟏𝟑
(𝟑)
= 𝑹𝟏𝟑
(𝟐)
+ 𝑹𝟏𝟑
𝟐
(𝑹𝟑𝟑
𝟐
)
∗
𝑹𝟑𝟑
𝟐
=ab+ab()∗=ab +ab
=ab
The Required Regular
Expression is 𝑹𝟏𝟑
(𝟑)
ab+ab = {ab,ab} = {ab} so that
RE is ab
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
25
DFA to RE Ex-2
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
26
Computation of k=0 and k=1
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
27
Computation of k=2
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
28
Computation of k=3
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
29
Finite Automata to Regular
Expressions
•
State Elimination Method
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
30
Finite Automata to RE
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
31
Finite Automata to RE -
Cont.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
32
Finite Automata to RE - Cont.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
33
Finite Automata to RE - Cont.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
34
Arden’s Theorem
• Let P and Q be two regular expressions.
• If P does not contain null string, then R = Q + RP has a unique
solution that is R = QP*
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
35
Ex 1
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
36
Ex2
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
37
Ex 3
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
38
Ex 4
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
39
Proving Languages not to be
regular
• Pumping Lemma
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
40
Applications of Pumping Lemma
Pumping Lemma is to be applied to show that certain languages
are not regular. It should never be used to show a language is
regular.
If L is regular, it satisfies Pumping Lemma.
If L does not satisfy Pumping Lemma, it is non-regular.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
41
Prove that L={anbn | n>=1} is
not regular
• L={ab,aabb,aaabbb,aaaabbbb,….}
• RE : aa*bb*
• FA:
• L={ab,aaaabb,abbbbb,….}
a
a
b
b
Proof by contradiction
Let L is regular with n states,
then,
w=“aaabbb” ꞓ L
According pumping lemma,
w divided into xyz,
Let
X=aa : y=abb : z= b
For k=2, compute xyk
z
=aa(abb)2b
=aaabbabbb not
belongs to L
So that L is not regular
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
42
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
43
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
44

More Related Content

What's hot

Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarMdImamHasan1
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture NotesFellowBuddy.com
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsAshutosh Pandey
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Srimatre K
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Chapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptChapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptFamiDan
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR Zahid Parvez
 

What's hot (20)

Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous Grammar
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Finite automata
Finite automataFinite automata
Finite automata
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal Forms
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Daa unit 4
Daa unit 4Daa unit 4
Daa unit 4
 
Chapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptChapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.ppt
 
Daa unit 5
Daa unit 5Daa unit 5
Daa unit 5
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 

Similar to Theory of Computation Unit 2

Higher order differential equation
Higher order differential equationHigher order differential equation
Higher order differential equationSooraj Maurya
 
Higher Order Differential Equation
Higher Order Differential EquationHigher Order Differential Equation
Higher Order Differential EquationShrey Patel
 
Logic (PROPOSITIONS)
Logic (PROPOSITIONS)Logic (PROPOSITIONS)
Logic (PROPOSITIONS)D Nayanathara
 
Lesson 21: More Algebra
Lesson 21: More AlgebraLesson 21: More Algebra
Lesson 21: More AlgebraKevin Johnson
 
Quadratic Functions.pptx
Quadratic Functions.pptxQuadratic Functions.pptx
Quadratic Functions.pptxMeryAnnMAlday
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
sequenceandseries-150221091317-conversion-gate01.pdf
sequenceandseries-150221091317-conversion-gate01.pdfsequenceandseries-150221091317-conversion-gate01.pdf
sequenceandseries-150221091317-conversion-gate01.pdfMuhammadJamil152989
 
Discrete mathematics presentation
Discrete mathematics presentationDiscrete mathematics presentation
Discrete mathematics presentationMdZiad
 
Algebra 2 unit 12.2.12.4
Algebra 2 unit 12.2.12.4Algebra 2 unit 12.2.12.4
Algebra 2 unit 12.2.12.4Mark Ryder
 
Kernels for Planar F-Deletion (Restricted Variants)
Kernels for Planar F-Deletion (Restricted Variants)Kernels for Planar F-Deletion (Restricted Variants)
Kernels for Planar F-Deletion (Restricted Variants)Neeldhara Misra
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFAMaulik Togadiya
 
090799768954
090799768954090799768954
090799768954FERNAN85
 

Similar to Theory of Computation Unit 2 (20)

Higher order differential equation
Higher order differential equationHigher order differential equation
Higher order differential equation
 
Higher Order Differential Equation
Higher Order Differential EquationHigher Order Differential Equation
Higher Order Differential Equation
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
Logic (PROPOSITIONS)
Logic (PROPOSITIONS)Logic (PROPOSITIONS)
Logic (PROPOSITIONS)
 
Lesson 21: More Algebra
Lesson 21: More AlgebraLesson 21: More Algebra
Lesson 21: More Algebra
 
Quadratic Functions.pptx
Quadratic Functions.pptxQuadratic Functions.pptx
Quadratic Functions.pptx
 
Vj
VjVj
Vj
 
L16
L16L16
L16
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
sequenceandseries-150221091317-conversion-gate01.pdf
sequenceandseries-150221091317-conversion-gate01.pdfsequenceandseries-150221091317-conversion-gate01.pdf
sequenceandseries-150221091317-conversion-gate01.pdf
 
Discrete mathematics presentation
Discrete mathematics presentationDiscrete mathematics presentation
Discrete mathematics presentation
 
regular expression
regular expressionregular expression
regular expression
 
Algebra 2 unit 12.2.12.4
Algebra 2 unit 12.2.12.4Algebra 2 unit 12.2.12.4
Algebra 2 unit 12.2.12.4
 
Sequence and series
Sequence and seriesSequence and series
Sequence and series
 
Kernels for Planar F-Deletion (Restricted Variants)
Kernels for Planar F-Deletion (Restricted Variants)Kernels for Planar F-Deletion (Restricted Variants)
Kernels for Planar F-Deletion (Restricted Variants)
 
Presentation
PresentationPresentation
Presentation
 
Unit i
Unit iUnit i
Unit i
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
090799768954
090799768954090799768954
090799768954
 

More from Jena Catherine Bel D (7)

Compiler Design Unit 5
Compiler Design Unit 5Compiler Design Unit 5
Compiler Design Unit 5
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
 
Theory of Computation Unit 4
Theory of Computation Unit 4Theory of Computation Unit 4
Theory of Computation Unit 4
 
Automata
AutomataAutomata
Automata
 

Recently uploaded

ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 

Recently uploaded (20)

ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 

Theory of Computation Unit 2

  • 1. UNIT II REGULAR EXPRESSIONS AND LANGUAGES Mrs.D.Jena Catherine Bel, Assistant Professor, CSE, Velammal Engineering College Mrs.D.Jena Catherine Bel, AP/CSE, VEC 1
  • 2. UNIT II REGULAR EXPRESSIONS AND LANGUAGES Regular Expressions – FA and Regular Expressions – Proving Languages not to be regular – Closure Properties of Regular Languages – Equivalence and Minimization of Automata. Mrs.D.Jena Catherine Bel, AP/CSE, VEC 2
  • 5. Regular Expressions • The algebraic notations describes exactly the same language as finite automata • The language described by regular expression or a finite automata is known as regular languages • The regular expression operators are union, concatenation and closure Mrs.D.Jena Catherine Bel, AP/CSE, VEC 5
  • 6. Let Regular expression R, then Regular language L(R) defined as follows: • L(Φ)= Φ • L()={} Let Alphabet ∑={a,b} • If R=a then L(a)={a} • If R=b then L(b)={b} Mrs.D.Jena Catherine Bel, AP/CSE, VEC 6
  • 7. Example RE Representation RL a+b L(a)U L(b) -> {a} U {b} {a,b} ab+bc L(ab)U L(bc) -> {ab} U {bc} {ab,bc} (a+b).c L(a+b).L(c) -> {a,b}.{c} {ac,bc} a(0+1)b L(a).L(0+1).L(b) {a}.{0,1}.{b} {a0b,a1b} (a+b)(0+1) L(a+b).L(0+1) ->{a,b}.{0,1} {a0,a1,b0,b1} Mrs.D.Jena Catherine Bel, AP/CSE, VEC 7
  • 8. Operators of Regular expression • Union • L = {01 , 10} • M = {ε ,00, 11} • L U M = {ε ,00, 11,01,10} • Concatenation • L = {01 , 10} • M = {ε ,00, 11} • L M = {01, 10, 0100, 1000, 0111, 1011} Mrs.D.Jena Catherine Bel, AP/CSE, VEC 8
  • 9. • Closure • L = {01 , 10} • L * = {ε, 01, 10, 0101,010101,0110,1001,…….} • L+ = {01, 10, 0101,010101,0110,1001,…….} Mrs.D.Jena Catherine Bel, AP/CSE, VEC 9
  • 10. Example • Give the regular expression for set of all strings starting with 0. • Give the regular expression for set of all strings ending with 0. • Mrs.D.Jena Catherine Bel, AP/CSE, VEC 10
  • 11. Example • Give the regular expression for set of all strings ending with 00. • Give the regular expression for set of all strings starting with 0 and ending with 1 Mrs.D.Jena Catherine Bel, AP/CSE, VEC 11
  • 18. FA to RE - Methods 1.Using Rij formula (Transitive closure method) 2. State Elimination Method 3. Arden’s Method Mrs.D.Jena Catherine Bel, AP/CSE, VEC 18
  • 19. Rij Method • DFA states are defined as {1,2,3,4,. . . n} • k={0,1,2,3,4,. . . n} • Rij Formula : 𝐑𝐢𝐣 (𝐤) = 𝐑𝐢𝐣 (𝐤−𝟏) + 𝐑𝐢𝐤 𝐤−𝟏 𝐑𝐤𝐤 𝐤−𝟏 ∗ 𝐑𝐤𝐣 (𝐤−𝟏) • i is the initial state (1) , j is the final state ꞓ F • The required RE is sum of union of 𝑹𝒊𝒋 (𝒏) such that j is the accepting state 𝑹𝒊𝒋 (𝒏) is computed by, 𝑹𝒊𝒋 (𝒌=𝟎) , 𝑹𝒊𝒋 (𝒌=𝟏) . . . 𝑹𝒊𝒋 (𝒌=𝒏) Mrs.D.Jena Catherine Bel, AP/CSE, VEC 19
  • 20. Properties of Regular Expression • Commutative: • R+S = S+R • Associative: • (R+S)+T = R+(S+T) • (RS)T = R(ST) • Identity: • R+Φ = R •  R = R  = R • Annihilator: • ΦR = RΦ = Φ ◦ Distributive: ◦ R(S+T) = RS + RT ◦ (R+S)T = RT+ST ◦ Idempotent: R+ R = R ◦ Involving Kleene closures: ◦ (R*)* = R* ◦ Φ* =  ◦ * =  ◦ R+ =RR* ◦ R? =  +R ◦  +R* = R* Mrs.D.Jena Catherine Bel, AP/CSE, VEC 20
  • 21. DFA to RE Ex-1 • DFA: Start state =1 Final state=3 • Total Number of nodes (n) = 3 & k={0,1,2,3} • The required regular expression is 1 2 3 a b 𝑹𝒊𝒋 (𝒏) 𝑹𝟏𝟑 (𝟑) 𝐑𝐢𝐣 (𝐤) = 𝐑𝐢𝐣 (𝐤−𝟏) + 𝐑𝐢𝐤 𝐤−𝟏 𝐑𝐤𝐤 𝐤−𝟏 ∗ 𝐑𝐤𝐣 (𝐤−𝟏) i.e i=1 , j=3 ,k=3 𝐑𝟏𝟑 (𝟑) = 𝐑𝟏𝟑 (𝟐) + 𝐑𝟏𝟑 𝟐 𝐑𝟑𝟑 𝟐 ∗ 𝐑𝟑𝟑 (𝟐) Mrs.D.Jena Catherine Bel, AP/CSE, VEC 21
  • 22. Computation of K=0 1 2 3 a b 𝑹𝟏𝟏 (𝟎) 𝑹𝟏𝟑 (𝟎) 𝑹𝟏𝟐 (𝟎) 𝑹𝟐𝟏 (𝟎) 𝑹𝟐𝟐 (𝟎) 𝑹𝟐𝟑 (𝟎) 𝑹𝟑𝟏 (𝟎) 𝑹𝟑𝟐 (𝟎) 𝑹𝟑𝟑 (𝟎) Mrs.D.Jena Catherine Bel, AP/CSE, VEC 22
  • 23. Computation of K=0 - cont. 1 2 3 a b 𝑹𝟏𝟏 (𝟎) =  𝑹𝟏𝟑 (𝟎) = Φ 𝑹𝟏𝟐 (𝟎) = 𝒂 𝑹𝟐𝟏 (𝟎) = Φ 𝑹𝟐𝟐 (𝟎) =  𝑹𝟐𝟑 (𝟎) = 𝒃 𝑹𝟑𝟏 (𝟎) = Φ 𝑹𝟑𝟐 (𝟎) = Φ 𝑹𝟑𝟑 (𝟎) =  Mrs.D.Jena Catherine Bel, AP/CSE, VEC 23
  • 24. Computation of K=1 𝑹𝟏𝟏 (𝟏) = 𝑹𝟏𝟏 (𝟎) + 𝑹𝟏𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟏 𝟎 = +  ()∗  =  𝑹𝟏𝟑 (𝟏) = 𝑹𝟏𝟑 (𝟎) + 𝑹𝟏𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟑 𝟎 =Φ+  ()∗Φ=Φ 𝑹𝟏𝟐 (𝟏) = 𝑹𝟏𝟐 (𝟎) + 𝑹𝟏𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟐 𝟎 = 𝒂+  ()∗ 𝐚 = a+a=a 𝑹𝟐𝟏 (𝟏) = 𝑹𝟐𝟏 (𝟎) + 𝑹𝟐𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟏 𝟎 =Φ+ Φ()∗  =Φ 𝑹𝟐𝟑 (𝟏) = 𝑹𝟐𝟑 (𝟎) + 𝑹𝟐𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟑 𝟎 =b+Φ= 𝒃 𝑹𝟐𝟐 (𝟏) = 𝑹𝟐𝟐 (𝟎) + 𝑹𝟐𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟐 𝟎 =  +Φ=  𝑹𝟑𝟑 (𝟏) = 𝑹𝟑𝟑 (𝟎) + 𝑹𝟑𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟑 𝟎 =  +Φ=  𝑹𝟑𝟐 (𝟏) = 𝑹𝟑𝟐 (𝟎) + 𝑹𝟑𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟑 𝟎 =Φ+Φ=Φ 𝑹𝟑𝟏 (𝟏) = 𝑹𝟑𝟏 (𝟎) + 𝑹𝟑𝟏 𝟎 (𝑹𝟏𝟏 𝟎 ) ∗ 𝑹𝟏𝟏 𝟎 =Φ+ Φ =Φ a+a = {a,a} = {a} so that RE is a Mrs.D.Jena Catherine Bel, AP/CSE, VEC 24
  • 25. Computation of K=2 and K=3 𝑹𝟏𝟑 (𝟐) = 𝑹𝟏𝟑 (𝟏) + 𝑹𝟏𝟐 𝟏 (𝑹𝟐𝟐 𝟏 ) ∗ 𝑹𝟐𝟑 𝟏 =Φ+ a()∗b=ab 𝑹𝟑𝟑 (𝟐) = 𝑹𝟑𝟑 (𝟏) + 𝑹𝟑𝟐 𝟏 (𝑹𝟐𝟐 𝟏 ) ∗ 𝑹𝟐𝟑 𝟏 =  +Φ=  𝑹𝟏𝟑 (𝟑) = 𝑹𝟏𝟑 (𝟐) + 𝑹𝟏𝟑 𝟐 (𝑹𝟑𝟑 𝟐 ) ∗ 𝑹𝟑𝟑 𝟐 =ab+ab()∗=ab +ab =ab The Required Regular Expression is 𝑹𝟏𝟑 (𝟑) ab+ab = {ab,ab} = {ab} so that RE is ab Mrs.D.Jena Catherine Bel, AP/CSE, VEC 25
  • 26. DFA to RE Ex-2 Mrs.D.Jena Catherine Bel, AP/CSE, VEC 26
  • 27. Computation of k=0 and k=1 Mrs.D.Jena Catherine Bel, AP/CSE, VEC 27
  • 30. Finite Automata to Regular Expressions • State Elimination Method Mrs.D.Jena Catherine Bel, AP/CSE, VEC 30
  • 31. Finite Automata to RE Mrs.D.Jena Catherine Bel, AP/CSE, VEC 31
  • 32. Finite Automata to RE - Cont. Mrs.D.Jena Catherine Bel, AP/CSE, VEC 32
  • 33. Finite Automata to RE - Cont. Mrs.D.Jena Catherine Bel, AP/CSE, VEC 33
  • 34. Finite Automata to RE - Cont. Mrs.D.Jena Catherine Bel, AP/CSE, VEC 34
  • 35. Arden’s Theorem • Let P and Q be two regular expressions. • If P does not contain null string, then R = Q + RP has a unique solution that is R = QP* Mrs.D.Jena Catherine Bel, AP/CSE, VEC 35
  • 40. Proving Languages not to be regular • Pumping Lemma Mrs.D.Jena Catherine Bel, AP/CSE, VEC 40
  • 41. Applications of Pumping Lemma Pumping Lemma is to be applied to show that certain languages are not regular. It should never be used to show a language is regular. If L is regular, it satisfies Pumping Lemma. If L does not satisfy Pumping Lemma, it is non-regular. Mrs.D.Jena Catherine Bel, AP/CSE, VEC 41
  • 42. Prove that L={anbn | n>=1} is not regular • L={ab,aabb,aaabbb,aaaabbbb,….} • RE : aa*bb* • FA: • L={ab,aaaabb,abbbbb,….} a a b b Proof by contradiction Let L is regular with n states, then, w=“aaabbb” ꞓ L According pumping lemma, w divided into xyz, Let X=aa : y=abb : z= b For k=2, compute xyk z =aa(abb)2b =aaabbabbb not belongs to L So that L is not regular Mrs.D.Jena Catherine Bel, AP/CSE, VEC 42