SlideShare a Scribd company logo
1 of 22
REGULAR EXPRESSIONS
M RATNAKAR BABU
Asst.Prof. CSE
Introduction
โ€ข The Language accepted by finite automata are easily described by
simple expressions called regular expressions.
โ€ข The regular expression is the most effective way to represent any
language.
โ€ข The language accepted by some regular expression is known as a
regular language.
Regular Expressions
1. Any terminal symbol(i.e. an element of โˆ‘), ๊œช and ฯ† are regular
expressions.
2. The union of two regular expressions R1 and R2, written as R1+R2, is
also a regular expression.
3. The concatenation of two regular expressions R1 and R2, written as
R1R2, is also a regular expression.
4. The iteration(or Closure) of a regular expression R, written as R* is
also a regular expression.
5. If R is a regular expression , then (R) is also a regular expression.
Identity Rules :
Let P,Q and R are the regular expressions then the identity rules are as
follows:
1. ฯ† +R = R
2. ฯ†R = Rฯ† = ฯ†
3. ๊œชR = R๊œช = R
4. ๊œช* = ๊œช and ฯ† *= ๊œช
5. R + R = R
6. R*R* = R*
7. RR* = R*R
8. (R*)*=R*
9. ๊œช + RR*= R* = ๊œช +R*R
10. (PQ)*P = P(QP)*
11. (P+Q)* = (P*Q*)* = (P* + Q*)
12. (P+Q)R = PR + QR and R(P+Q) = RP + RQ
Regular Expressions
โ€ข Exercise 2: Construct the regular expression for the language which accepts
all the strings which begin or end with either 00 or 11.
Solution:
The R.E. can be categorized into two subparts.
R = L1 + L2
L1 = The String which begin with 00 or 11.
L2 = The String which end with 00 or 11.
Let us find out L1 and L2.
L1 = (00+11)( any number of 0โ€™s and 1โ€™s )
L1 = (00+11)(0+1)*
L2 = ( any number of 0โ€™s and 1โ€™s ) (00+11)
L2 = (0+1)*(00+11)
Hence
R = [(00+11)(0+1)*] + [(0+1)*(00+11)]
Regular Expressions
Algorithm to build R.E. from given DFA
1. Let q1 be the initial state.
2. There are q2,q3,q4,โ€ฆ.qn number of states. The final state may be
some qj where j<=n.
3. Let ๏กji represents the transition from qj to qi.
4. Calculate qi such that
qi = ๏กji .qj
If qi is a start state
qi = ๏กji .qj +๊œช
5. Similarly compute the final state which ultimately gives the regular
expression r.
โ€ข Exercise 1: Write a regular expression for the set of strings that
contains an even number of 1โ€™s over ๏ƒฅ={0,1}. Treat zero 1โ€™s as an
even number.
Solution:
The regular expression for the above F.A. is 0*10*1
Regular Expressions
Q0 Q1
1
0 0
1
DFA to RE via State Elimination (1)
1. Starting with intermediate states and then moving to accepting
states, apply the state elimination process to produce an equivalent
automaton with regular expression labels on the edges.
โ€ข The result will be a one or two state automaton with a start state and
accepting state.
DFA to RE State Elimination (2)
2. If the two states are different, we will have
an automaton that looks like the following:
Start
S
R
T
U
We can describe this automaton as: (R+SU*T)*SU*
DFA to RE State Elimination (3)
3. If the start state is also an accepting state, then we must
also perform a state elimination from the original
automaton that gets rid of every state but the start state.
This leaves the following:
Start
R
We can describe this automaton as simply R*.
DFA to RE State Elimination (4)
4. If there are n accepting states, we must repeat the above steps for
each accepting states to get n different regular expressions, R1, R2,
โ€ฆ Rn.
5. For each repeat we turn any other accepting state to non-
accepting.
6. The desired regular expression for the automaton is then the union
of each of the n regular expressions: R1๏ƒˆ R2โ€ฆ ๏ƒˆ RN
DFA๏ƒ RE Example
โ€ข Convert the following to a RE
โ€ข First convert the edges to REโ€™s:
3Start 1 2
1 1
0
0
0,1
3Start 1 2
1 1
0
0
0+1
DFA ๏ƒ  RE Example (2)
โ€ข Eliminate State 1:
โ€ข To:
Start
0
0
3 1 2
1 1
0+1
3Start 2
11
0+10 0+1
Note edge from 3๏ƒ 3
Answer: (0+10)*11(0+1)*
Second Example
โ€ข Automata that accepts even number of 1โ€™s
โ€ข Eliminate state 2:
1Start 2 3
1 1
0
1
00
0+10*1
1Start 3
0
10*1
Second Example (2)
โ€ข Two accepting states, turn off state 3 first
1Start 3
0 0+10*1
10*1
This is just 0*; can ignore going to state 3 since we would โ€œdieโ€
1Start
0
3
0+10*1
10*1
Second Example (3)
โ€ข Turn off state 1 second:
1Start 3
0 0+10*1
10*1
This is just 0*10*1(0+10*1)*
Combine from previous slide to get
0* + 0*10*1(0+10*1)*
0+10*1
1Start 3
0
10*1
Converting a RE to an Automata
โ€ข We have shown we can convert an automata to a RE. To show
equivalence we must also go the other direction, convert a RE to
an automaton.
โ€ข We can do this easiest by converting a RE to an ฮต-NFA
RE to ฮต-NFA
โ€ข Basis:
R=a
R=ฮต ฮต
R=ร˜
a
Next slide: More complex REโ€™s
R=S+T
S
T
ฮต
ฮต
ฮต
ฮต
R=ST
S T
ฮต
R=S*
ฮต
S
ฮต
ฮต
ฮต
RE to ฮต-NFA Example
โ€ข Convert R= (ab+a)* to an NFA
โ€ข We proceed in stages, starting from simple elements and working our way up
a
a
b
b
ab
a bฮต
RE to ฮต-NFA Example (2)
ab+a
(ab+a)*
a bฮต
a
ฮต
ฮต
ฮต
ฮต
a bฮต
a
ฮต
ฮต
ฮต
ฮต
ฮตฮต
ฮต
ฮต
End for Now
Continue in Next Class

More Related Content

What's hot

Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
ย 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3VenkataRaoS1
ย 
POSTโ€™s CORRESPONDENCE PROBLEM
POSTโ€™s CORRESPONDENCE PROBLEMPOSTโ€™s CORRESPONDENCE PROBLEM
POSTโ€™s CORRESPONDENCE PROBLEMRajendran
ย 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysisAkshaya Arunan
ย 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesMarina Santini
ย 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
ย 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of LanguageDipankar Boruah
ย 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automatadeepinderbedi
ย 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
ย 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theoremSamita Mukesh
ย 
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
ย 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokensDattatray Gandhmal
ย 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
ย 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysisDattatray Gandhmal
ย 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFAMaulik Togadiya
ย 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theorySampath Kumar S
ย 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite AutomataArchana Gopinath
ย 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOCMaulik Togadiya
ย 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTanzeela_Hussain
ย 

What's hot (20)

Regular Languages
Regular LanguagesRegular Languages
Regular Languages
ย 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
ย 
POSTโ€™s CORRESPONDENCE PROBLEM
POSTโ€™s CORRESPONDENCE PROBLEMPOSTโ€™s CORRESPONDENCE PROBLEM
POSTโ€™s CORRESPONDENCE PROBLEM
ย 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
ย 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
ย 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
ย 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
ย 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
ย 
Propositional logic
Propositional logicPropositional logic
Propositional logic
ย 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
ย 
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
ย 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
ย 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
ย 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
ย 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
ย 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
ย 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
ย 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
ย 
Finite automata
Finite automataFinite automata
Finite automata
ย 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
ย 

Similar to Regular expressions

Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Srimatre K
ย 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2VenkataRaoS1
ย 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaRushabh2428
ย 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptxviswanath kani
ย 
Unit ii
Unit iiUnit ii
Unit iiTPLatchoumi
ย 
Regular expression
Regular expressionRegular expression
Regular expressionMONIRUL ISLAM
ย 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.pptMDSayem35
ย 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.pptProvatMajhi
ย 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
ย 
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...ArjunMehra32
ย 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdfImranBhatti58
ย 
regular expression
regular expressionregular expression
regular expressionRohitKumar596173
ย 
re1.ppt
re1.pptre1.ppt
re1.pptPEzhumalai
ย 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)pepe3059
ย 

Similar to Regular expressions (20)

Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2
ย 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
ย 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
ย 
FLAT.pdf
FLAT.pdfFLAT.pdf
FLAT.pdf
ย 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
ย 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
ย 
Unit ii
Unit iiUnit ii
Unit ii
ย 
Regular expression
Regular expressionRegular expression
Regular expression
ย 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
ย 
unit 2 part b.docx
unit 2 part b.docxunit 2 part b.docx
unit 2 part b.docx
ย 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
ย 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
ย 
Turing Machine
Turing MachineTuring Machine
Turing Machine
ย 
L08a
L08aL08a
L08a
ย 
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...
PPT 2.1.1(The Pumping Lemma for Regular sets, Application of the Pumping Lemm...
ย 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
ย 
regular expression
regular expressionregular expression
regular expression
ย 
PART B.docx
PART B.docxPART B.docx
PART B.docx
ย 
re1.ppt
re1.pptre1.ppt
re1.ppt
ย 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
ย 

More from Ratnakar Mikkili

AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptxRatnakar Mikkili
ย 
AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptxRatnakar Mikkili
ย 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxRatnakar Mikkili
ย 
Artificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxArtificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxRatnakar Mikkili
ย 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.pptRatnakar Mikkili
ย 
2_4 Finite Automata.ppt
2_4 Finite Automata.ppt2_4 Finite Automata.ppt
2_4 Finite Automata.pptRatnakar Mikkili
ย 
Push down automata
Push down automataPush down automata
Push down automataRatnakar Mikkili
ย 
Context free grammar
Context free grammarContext free grammar
Context free grammarRatnakar Mikkili
ย 

More from Ratnakar Mikkili (8)

AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptx
ย 
AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptx
ย 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptx
ย 
Artificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxArtificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptx
ย 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
ย 
2_4 Finite Automata.ppt
2_4 Finite Automata.ppt2_4 Finite Automata.ppt
2_4 Finite Automata.ppt
ย 
Push down automata
Push down automataPush down automata
Push down automata
ย 
Context free grammar
Context free grammarContext free grammar
Context free grammar
ย 

Recently uploaded

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
ย 
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night StandCall Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Standamitlee9823
ย 
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
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
ย 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
ย 
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
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
ย 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
ย 
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
ย 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
ย 
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
ย 

Recently uploaded (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night StandCall Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
Call Girls In Bangalore โ˜Ž 7737669865 ๐Ÿฅต Book Your One night Stand
ย 
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...
ย 
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
ย 
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
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
ย 
(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
ย 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
ย 
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
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
ย 
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)
ย 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
ย 
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...
ย 

Regular expressions

  • 1. REGULAR EXPRESSIONS M RATNAKAR BABU Asst.Prof. CSE
  • 2. Introduction โ€ข The Language accepted by finite automata are easily described by simple expressions called regular expressions. โ€ข The regular expression is the most effective way to represent any language. โ€ข The language accepted by some regular expression is known as a regular language.
  • 3. Regular Expressions 1. Any terminal symbol(i.e. an element of โˆ‘), ๊œช and ฯ† are regular expressions. 2. The union of two regular expressions R1 and R2, written as R1+R2, is also a regular expression. 3. The concatenation of two regular expressions R1 and R2, written as R1R2, is also a regular expression. 4. The iteration(or Closure) of a regular expression R, written as R* is also a regular expression. 5. If R is a regular expression , then (R) is also a regular expression.
  • 4. Identity Rules : Let P,Q and R are the regular expressions then the identity rules are as follows: 1. ฯ† +R = R 2. ฯ†R = Rฯ† = ฯ† 3. ๊œชR = R๊œช = R 4. ๊œช* = ๊œช and ฯ† *= ๊œช 5. R + R = R 6. R*R* = R* 7. RR* = R*R 8. (R*)*=R* 9. ๊œช + RR*= R* = ๊œช +R*R 10. (PQ)*P = P(QP)* 11. (P+Q)* = (P*Q*)* = (P* + Q*) 12. (P+Q)R = PR + QR and R(P+Q) = RP + RQ Regular Expressions
  • 5. โ€ข Exercise 2: Construct the regular expression for the language which accepts all the strings which begin or end with either 00 or 11. Solution: The R.E. can be categorized into two subparts. R = L1 + L2 L1 = The String which begin with 00 or 11. L2 = The String which end with 00 or 11. Let us find out L1 and L2. L1 = (00+11)( any number of 0โ€™s and 1โ€™s ) L1 = (00+11)(0+1)* L2 = ( any number of 0โ€™s and 1โ€™s ) (00+11) L2 = (0+1)*(00+11) Hence R = [(00+11)(0+1)*] + [(0+1)*(00+11)] Regular Expressions
  • 6. Algorithm to build R.E. from given DFA 1. Let q1 be the initial state. 2. There are q2,q3,q4,โ€ฆ.qn number of states. The final state may be some qj where j<=n. 3. Let ๏กji represents the transition from qj to qi. 4. Calculate qi such that qi = ๏กji .qj If qi is a start state qi = ๏กji .qj +๊œช 5. Similarly compute the final state which ultimately gives the regular expression r.
  • 7. โ€ข Exercise 1: Write a regular expression for the set of strings that contains an even number of 1โ€™s over ๏ƒฅ={0,1}. Treat zero 1โ€™s as an even number. Solution: The regular expression for the above F.A. is 0*10*1 Regular Expressions Q0 Q1 1 0 0 1
  • 8. DFA to RE via State Elimination (1) 1. Starting with intermediate states and then moving to accepting states, apply the state elimination process to produce an equivalent automaton with regular expression labels on the edges. โ€ข The result will be a one or two state automaton with a start state and accepting state.
  • 9. DFA to RE State Elimination (2) 2. If the two states are different, we will have an automaton that looks like the following: Start S R T U We can describe this automaton as: (R+SU*T)*SU*
  • 10. DFA to RE State Elimination (3) 3. If the start state is also an accepting state, then we must also perform a state elimination from the original automaton that gets rid of every state but the start state. This leaves the following: Start R We can describe this automaton as simply R*.
  • 11. DFA to RE State Elimination (4) 4. If there are n accepting states, we must repeat the above steps for each accepting states to get n different regular expressions, R1, R2, โ€ฆ Rn. 5. For each repeat we turn any other accepting state to non- accepting. 6. The desired regular expression for the automaton is then the union of each of the n regular expressions: R1๏ƒˆ R2โ€ฆ ๏ƒˆ RN
  • 12. DFA๏ƒ RE Example โ€ข Convert the following to a RE โ€ข First convert the edges to REโ€™s: 3Start 1 2 1 1 0 0 0,1 3Start 1 2 1 1 0 0 0+1
  • 13. DFA ๏ƒ  RE Example (2) โ€ข Eliminate State 1: โ€ข To: Start 0 0 3 1 2 1 1 0+1 3Start 2 11 0+10 0+1 Note edge from 3๏ƒ 3 Answer: (0+10)*11(0+1)*
  • 14. Second Example โ€ข Automata that accepts even number of 1โ€™s โ€ข Eliminate state 2: 1Start 2 3 1 1 0 1 00 0+10*1 1Start 3 0 10*1
  • 15. Second Example (2) โ€ข Two accepting states, turn off state 3 first 1Start 3 0 0+10*1 10*1 This is just 0*; can ignore going to state 3 since we would โ€œdieโ€ 1Start 0 3 0+10*1 10*1
  • 16. Second Example (3) โ€ข Turn off state 1 second: 1Start 3 0 0+10*1 10*1 This is just 0*10*1(0+10*1)* Combine from previous slide to get 0* + 0*10*1(0+10*1)* 0+10*1 1Start 3 0 10*1
  • 17. Converting a RE to an Automata โ€ข We have shown we can convert an automata to a RE. To show equivalence we must also go the other direction, convert a RE to an automaton. โ€ข We can do this easiest by converting a RE to an ฮต-NFA
  • 18. RE to ฮต-NFA โ€ข Basis: R=a R=ฮต ฮต R=ร˜ a Next slide: More complex REโ€™s
  • 20. RE to ฮต-NFA Example โ€ข Convert R= (ab+a)* to an NFA โ€ข We proceed in stages, starting from simple elements and working our way up a a b b ab a bฮต
  • 21. RE to ฮต-NFA Example (2) ab+a (ab+a)* a bฮต a ฮต ฮต ฮต ฮต a bฮต a ฮต ฮต ฮต ฮต ฮตฮต ฮต ฮต
  • 22. End for Now Continue in Next Class