SlideShare a Scribd company logo
1 of 28
Download to read offline
CHAPTER-3 REGULAR LANGUAGES
REGULAR EXPRESSION
Chapter 3
1
Regular Expressions
Regular expressions were mathematical tool designed to represent
regular languages.
Built from a set of primitives and operations.
This representation involves a combination of strings of symbols
from some alphabet Σ, parentheses and the operators +, ⋅, and *.
A regular expression is obtained from the symbol {a, b, c}, empty
string ∈, and empty-set ∅ perform the operations +, ⋅ and *
(union, concatenation and Kleene star).
2
Regular Expressions
Examples
0 + 1 represents the set {0, 1}
1 represents the set {1}
(0 +1)1 represents the set {01, 11}
(a+b)⋅(b+c) represents the set {ab, bb, ac, bc}
(0 + 1)* = ∈+ (0 + 1) + (0 + 1) (0 + 1)..........= Σ*
(0 + 1 )+ =(0 +1) (0 +1)*= Σ+ =Σ*- {ε}
3
Building Regular Expressions
Assume that Σ = {a,b,c}
Zero or more: a* means zero or more a‟s,
To say zero or more ab‟s, i.e.,{λ, ab,abab........,} you need to say (ab)*.
One or more: Since a* means zero or more a‟s, you can use aa*
(or equivalently a*a) to mean one or more a‟s.
Similarly to describe „one or more ab‟s”, that is {ab, abab,
ababab, .........}, you can use ab (ab)*.
Zero or one: It can be described as an optional „a‟ with (a + λ).
4
Languages defined by Regular Expressions
5
Hierarchy of evaluation of regular expression
6
 We follow the following order when evaluate a regular
expressions;
 Parenthesis
 Kleene Closure
 Concatenation
 Union
Regular Languages
Regular Languages are
Language accepted by a DFA.
A language 𝐿 is regular if there exists a DFA 𝐷 such
that 𝐿 = 𝐿(𝐷).
7
Regular Languages
 Let Σ be an alphabet. The class of “regular languages” over Σ is
defined inductively as follows:
a) ∅ is a regular language
b) For each 𝜎 ∈ Σ, {ζ}is a regular language
c) For any natural number n ≥ 2, if L1, L2, L3, .... ,Ln are regular
languages, then so is L1∪L2 ∪......∪ Ln.
d) For any natural number n ≥ 2, if L1 L2,...... Ln are regular
languages, then so is L1 L2 ...... Ln.
e) If L is a regular language, then so is L*.
(f) Nothing else is a regular language unless its construction
follows from rules (a) to (e).
8
Examples
i. ∅ is a regular language (by rule (a))
ii. L = {a, ab} is a language over Σ = {a, b}because, both {a} and
{b} are regular languages by rule (b).
{a} o {b}={ab} is a regular language. By rule (d)
{a }∪{ab } = L is a regular language. Using rule (c),
iii. The language over the alphabet {0,1} where strings contain an
even number of 0‟s can be constructed by
(1*((01*)(01*))*) or simply 1*(01* 01*)*.
9
Exercises
Solutions:
10
Regular Expressions to NFA
For any x in Σ, the regular expression denotes the language {x}.
The NFA (with a single start state and a single final state) as
shown below, represents exactly that language.
The regular expression λ denotes the language {λ}that is the
language containing only the empty string.
11
Regular Expressions to NFA
The regular expression ∅ denotes the language ∅; no
strings belong to this language, not even the empty
string.
For juxtaposition, strings in L(r1) followed by strings in L(r2)
, we chain the NFAs together
12
Regular Expressions to NFA
The “+” denotes “or” in a regular expression, we would use an
NFA with a choice of paths.
The star (*) denotes zero or more applications of the regular
expression, hence a loop has to be set up in the NFA.
13
Example :Construct An NFA for the regular expression (0+1)*.
14
 Solution: NFA is constructed step by step by breaking the RE.
 r3= (r1+r2)
 r=r3*, where r1=0, r2=1
Example
Represent the following sets by regular expression
a. {∧, ab}
b. {1,11,111....}
c. {ab, a, b, bb}
Solution
a. The set {∧, ab} is represented by the regular expression ∧ + ab
b. The set{1, 11,111,....,}is got by concatenating 1 and any
element of {1}*.
Therefore 1(1)* represent the given set.
c. The set {ab, a, b, bb} represents the regular expression
ab+ a+ b +bb.
15
Exercise
1. Obtain the regular expressions for the following sets:
1.1. The set of all strings over {a, b} beginning and ending with „a‟.
 The regular expression for ‘the set of all strings over {a, b}
beginning and ending with ‘a’ is given by: a (a + b)*a
1.2. {b2, b5, b8,. . . . .}
 The regular expression for {b 2 , b 5 , b 8 , ............} is given by:
bb (bbb)*
1.3. {a2n+1 |n > 0}
 The regular expression for {a 2n+1 |n > 0}is given by:
a (aa)+
16
FINITE AUTOMATA WITH OUTPUT
 A finite-state machine M = (Q , Σ, δ , λ, O , q0 ) consists of
 a finite set Q of states,
 a finite input alphabet Σ,
 a finite output alphabet O,
 a transition function δ that assigns to each state and input pair
of a new state,
 an output function λ that assigns to each state and input pair an
output, and
 an initial state q0.
17
 There are two types of finite state machines that generate
output −
 Mealy Machine
 Moore Machine
Mealy Machine
 A Mealy Machine is an FSM whose output depends on the
present state as well as the present input.
 It can be described by a 6 tuple (Q, ∑, O, δ, X, q0)
M = (Q , O , ,Σ , δ , λ , q0 ) consists of
 A finite set Q of states,
 A finite input alphabet Σ,
 A finite output alphabet O,
 A transition function δ that assigns to each
state and input pair a new state,
 An output function X that assigns to each
state and input pair an output, and
 An initial state q0.
18
Examples
The above Mealy Machine outputs a value for each input.
You can tell input /output.
So for the following input:
000101010
It outputs
000010101
19
Moore Machine
 Moore machine is an FSM whose outputs depend on only the
present state.
 A Moore machine can be described by a 6 tuple(Q, ∑, O, δ, X, q0)
20
Current State Input Next State Output
A 0 D 0
A 1 B 0
B 0 E 0
B 1 C 0
C 0 F 0
C 1 C 0
D 0 G 0
D 1 E 0
E 0 H 0
E 1 F 0
F 0 I 1
F 1 F 0
G 0 G 0
G 1 H 0
H 0 H 0
H 1 I 1
I 0 I 1
I 1 I 1
Fig Example Moore machine
21
PROPERTIES OF REGULAR SETS
(LANGUAGES)
 There are several operations defined on languages:
L1 ∪ L2: strings in either L1 or L2.
L1 ∩ L2 : strings in both L1 and L2.
L1L2 : strings composed of one string from L1, followed by one
string from L2.
L1*: Zero or more strings from L1 concatenated together
L1-L2 : strings in L1 that are not in L2.
L1
R : strings in L1, reversed.
22
Applying the Pumping Lemma
Theorem
Let L be a regular language. Then there exists a constant ‘c’ such that
for every string w in L −
|w| ≥ c
We can break w into three strings,
w = xyz, such that −
|y| > 0
|xy| ≤ c
For all k ≥ 0, the string xykz is also in L.
 The “pumping lemma” for regular languages is another way of
showing that a given infinite language is not regular.
23
Applications of Pumping Lemma
 Method to prove that a language L is not regular
 At first, we have to assume that L is regular.
 So, the pumping lemma should hold for L.
 Use the pumping lemma to obtain a contradiction −
 Select w such that |w| ≥ c
 Select y such that |y| ≥ 1
 Select x such that |xy| ≤ c
 Assign the remaining string to z.
 Select k such that the resulting string is not in L.
 Hence L is not regular.
24
Problem
Prove that L = {aibi | i ≥ 0} is not regular.
Solution: At first, assume that L is regular and n is the number of states.
Let w = anbn. Thus |w| = 2n ≥ n.
By pumping lemma, let w = xyz, where |xy|≤ n.
Let x = ap, y = aq, and z = arbn, where p + q + r = n.
p ≠ 0, q ≠ 0, r ≠ 0. Thus |y|≠ 0
Let k = 2. Then xy2z = apa2qarbn.
Number of as = (p + 2q + r) = (p + q + r) + q = n + q
Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
Thus, xy2z is not in L. Hence L is not regular.
25
Complement of a DFA
 If (Q, ∑, δ, q0, F) be a DFA that accepts a language L, then the
complement of the DFA can be obtained by swapping its
accepting states with its non-accepting states and vice versa.
 We will take an example and elaborate this below −
This DFA accepts the language
L = {a, aa, aaa , ............. }
over the alphabet
∑ = {a, b}
So, RE = a+.
26
Con..
Now we will swap its accepting states with its non-accepting states
and vice versa and will get the following −
This DFA accepts the language
Ľ = { ε , b, ab ,bb,ba, ............... } over the alphabet
∑ = {a, b}
27
Exercise
28
1. Let Σ = {a, b}.
 Let L = { w ∈ Σ* | w contains at most one a }.
 Which of the following is a regular expression for L?
A. Σ*aΣ*
B. b*ab* ∪ b*
C. b*(a ∪ ε)b*
D. b*a*b* ∪ b*
E. b*(a* ∪ ε)b*
F. None of the above, or two or more of the above.
2. Construct An NFA for the regular expression 1(11)*.

More Related Content

What's hot

Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)Naman Joshi
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesMarina Santini
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)Siddhesh Pange
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 
Chapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptChapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptFamiDan
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression BasicsEterna Han Tsai
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
 
Automata theory
Automata theoryAutomata theory
Automata theorycolleges
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16sumitbardhan
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Animesh Chaturvedi
 

What's hot (20)

Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Chapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptChapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.ppt
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression Basics
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Moore machine (automata)
Moore  machine (automata)Moore  machine (automata)
Moore machine (automata)
 

Similar to Chapter 3 REGULAR EXPRESSION.pdf

Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxRaviAr5
 
Automata
AutomataAutomata
AutomataGaditek
 
Automata
AutomataAutomata
AutomataGaditek
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...parmeet834
 
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurEnd semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurVivekananda Samiti
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring奕安 陳
 
Class1
 Class1 Class1
Class1issbp
 
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
 
Prin digcommselectedsoln
Prin digcommselectedsolnPrin digcommselectedsoln
Prin digcommselectedsolnAhmed Alshomi
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdfImranBhatti58
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFAMaulik Togadiya
 

Similar to Chapter 3 REGULAR EXPRESSION.pdf (20)

Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Automata
AutomataAutomata
Automata
 
Automata
AutomataAutomata
Automata
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurEnd semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
 
FLAT.pdf
FLAT.pdfFLAT.pdf
FLAT.pdf
 
regular expression
regular expressionregular expression
regular expression
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
 
Ch03
Ch03Ch03
Ch03
 
unit 2 part b.docx
unit 2 part b.docxunit 2 part b.docx
unit 2 part b.docx
 
Class1
 Class1 Class1
Class1
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
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
 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
 
Prin digcommselectedsoln
Prin digcommselectedsolnPrin digcommselectedsoln
Prin digcommselectedsoln
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Teori automata lengkap
Teori automata lengkapTeori automata lengkap
Teori automata lengkap
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 

Chapter 3 REGULAR EXPRESSION.pdf

  • 1. CHAPTER-3 REGULAR LANGUAGES REGULAR EXPRESSION Chapter 3 1
  • 2. Regular Expressions Regular expressions were mathematical tool designed to represent regular languages. Built from a set of primitives and operations. This representation involves a combination of strings of symbols from some alphabet Σ, parentheses and the operators +, ⋅, and *. A regular expression is obtained from the symbol {a, b, c}, empty string ∈, and empty-set ∅ perform the operations +, ⋅ and * (union, concatenation and Kleene star). 2
  • 3. Regular Expressions Examples 0 + 1 represents the set {0, 1} 1 represents the set {1} (0 +1)1 represents the set {01, 11} (a+b)⋅(b+c) represents the set {ab, bb, ac, bc} (0 + 1)* = ∈+ (0 + 1) + (0 + 1) (0 + 1)..........= Σ* (0 + 1 )+ =(0 +1) (0 +1)*= Σ+ =Σ*- {ε} 3
  • 4. Building Regular Expressions Assume that Σ = {a,b,c} Zero or more: a* means zero or more a‟s, To say zero or more ab‟s, i.e.,{λ, ab,abab........,} you need to say (ab)*. One or more: Since a* means zero or more a‟s, you can use aa* (or equivalently a*a) to mean one or more a‟s. Similarly to describe „one or more ab‟s”, that is {ab, abab, ababab, .........}, you can use ab (ab)*. Zero or one: It can be described as an optional „a‟ with (a + λ). 4
  • 5. Languages defined by Regular Expressions 5
  • 6. Hierarchy of evaluation of regular expression 6  We follow the following order when evaluate a regular expressions;  Parenthesis  Kleene Closure  Concatenation  Union
  • 7. Regular Languages Regular Languages are Language accepted by a DFA. A language 𝐿 is regular if there exists a DFA 𝐷 such that 𝐿 = 𝐿(𝐷). 7
  • 8. Regular Languages  Let Σ be an alphabet. The class of “regular languages” over Σ is defined inductively as follows: a) ∅ is a regular language b) For each 𝜎 ∈ Σ, {ζ}is a regular language c) For any natural number n ≥ 2, if L1, L2, L3, .... ,Ln are regular languages, then so is L1∪L2 ∪......∪ Ln. d) For any natural number n ≥ 2, if L1 L2,...... Ln are regular languages, then so is L1 L2 ...... Ln. e) If L is a regular language, then so is L*. (f) Nothing else is a regular language unless its construction follows from rules (a) to (e). 8
  • 9. Examples i. ∅ is a regular language (by rule (a)) ii. L = {a, ab} is a language over Σ = {a, b}because, both {a} and {b} are regular languages by rule (b). {a} o {b}={ab} is a regular language. By rule (d) {a }∪{ab } = L is a regular language. Using rule (c), iii. The language over the alphabet {0,1} where strings contain an even number of 0‟s can be constructed by (1*((01*)(01*))*) or simply 1*(01* 01*)*. 9
  • 11. Regular Expressions to NFA For any x in Σ, the regular expression denotes the language {x}. The NFA (with a single start state and a single final state) as shown below, represents exactly that language. The regular expression λ denotes the language {λ}that is the language containing only the empty string. 11
  • 12. Regular Expressions to NFA The regular expression ∅ denotes the language ∅; no strings belong to this language, not even the empty string. For juxtaposition, strings in L(r1) followed by strings in L(r2) , we chain the NFAs together 12
  • 13. Regular Expressions to NFA The “+” denotes “or” in a regular expression, we would use an NFA with a choice of paths. The star (*) denotes zero or more applications of the regular expression, hence a loop has to be set up in the NFA. 13
  • 14. Example :Construct An NFA for the regular expression (0+1)*. 14  Solution: NFA is constructed step by step by breaking the RE.  r3= (r1+r2)  r=r3*, where r1=0, r2=1
  • 15. Example Represent the following sets by regular expression a. {∧, ab} b. {1,11,111....} c. {ab, a, b, bb} Solution a. The set {∧, ab} is represented by the regular expression ∧ + ab b. The set{1, 11,111,....,}is got by concatenating 1 and any element of {1}*. Therefore 1(1)* represent the given set. c. The set {ab, a, b, bb} represents the regular expression ab+ a+ b +bb. 15
  • 16. Exercise 1. Obtain the regular expressions for the following sets: 1.1. The set of all strings over {a, b} beginning and ending with „a‟.  The regular expression for ‘the set of all strings over {a, b} beginning and ending with ‘a’ is given by: a (a + b)*a 1.2. {b2, b5, b8,. . . . .}  The regular expression for {b 2 , b 5 , b 8 , ............} is given by: bb (bbb)* 1.3. {a2n+1 |n > 0}  The regular expression for {a 2n+1 |n > 0}is given by: a (aa)+ 16
  • 17. FINITE AUTOMATA WITH OUTPUT  A finite-state machine M = (Q , Σ, δ , λ, O , q0 ) consists of  a finite set Q of states,  a finite input alphabet Σ,  a finite output alphabet O,  a transition function δ that assigns to each state and input pair of a new state,  an output function λ that assigns to each state and input pair an output, and  an initial state q0. 17
  • 18.  There are two types of finite state machines that generate output −  Mealy Machine  Moore Machine Mealy Machine  A Mealy Machine is an FSM whose output depends on the present state as well as the present input.  It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) M = (Q , O , ,Σ , δ , λ , q0 ) consists of  A finite set Q of states,  A finite input alphabet Σ,  A finite output alphabet O,  A transition function δ that assigns to each state and input pair a new state,  An output function X that assigns to each state and input pair an output, and  An initial state q0. 18
  • 19. Examples The above Mealy Machine outputs a value for each input. You can tell input /output. So for the following input: 000101010 It outputs 000010101 19
  • 20. Moore Machine  Moore machine is an FSM whose outputs depend on only the present state.  A Moore machine can be described by a 6 tuple(Q, ∑, O, δ, X, q0) 20
  • 21. Current State Input Next State Output A 0 D 0 A 1 B 0 B 0 E 0 B 1 C 0 C 0 F 0 C 1 C 0 D 0 G 0 D 1 E 0 E 0 H 0 E 1 F 0 F 0 I 1 F 1 F 0 G 0 G 0 G 1 H 0 H 0 H 0 H 1 I 1 I 0 I 1 I 1 I 1 Fig Example Moore machine 21
  • 22. PROPERTIES OF REGULAR SETS (LANGUAGES)  There are several operations defined on languages: L1 ∪ L2: strings in either L1 or L2. L1 ∩ L2 : strings in both L1 and L2. L1L2 : strings composed of one string from L1, followed by one string from L2. L1*: Zero or more strings from L1 concatenated together L1-L2 : strings in L1 that are not in L2. L1 R : strings in L1, reversed. 22
  • 23. Applying the Pumping Lemma Theorem Let L be a regular language. Then there exists a constant ‘c’ such that for every string w in L − |w| ≥ c We can break w into three strings, w = xyz, such that − |y| > 0 |xy| ≤ c For all k ≥ 0, the string xykz is also in L.  The “pumping lemma” for regular languages is another way of showing that a given infinite language is not regular. 23
  • 24. Applications of Pumping Lemma  Method to prove that a language L is not regular  At first, we have to assume that L is regular.  So, the pumping lemma should hold for L.  Use the pumping lemma to obtain a contradiction −  Select w such that |w| ≥ c  Select y such that |y| ≥ 1  Select x such that |xy| ≤ c  Assign the remaining string to z.  Select k such that the resulting string is not in L.  Hence L is not regular. 24
  • 25. Problem Prove that L = {aibi | i ≥ 0} is not regular. Solution: At first, assume that L is regular and n is the number of states. Let w = anbn. Thus |w| = 2n ≥ n. By pumping lemma, let w = xyz, where |xy|≤ n. Let x = ap, y = aq, and z = arbn, where p + q + r = n. p ≠ 0, q ≠ 0, r ≠ 0. Thus |y|≠ 0 Let k = 2. Then xy2z = apa2qarbn. Number of as = (p + 2q + r) = (p + q + r) + q = n + q Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn. Thus, xy2z is not in L. Hence L is not regular. 25
  • 26. Complement of a DFA  If (Q, ∑, δ, q0, F) be a DFA that accepts a language L, then the complement of the DFA can be obtained by swapping its accepting states with its non-accepting states and vice versa.  We will take an example and elaborate this below − This DFA accepts the language L = {a, aa, aaa , ............. } over the alphabet ∑ = {a, b} So, RE = a+. 26
  • 27. Con.. Now we will swap its accepting states with its non-accepting states and vice versa and will get the following − This DFA accepts the language Ľ = { ε , b, ab ,bb,ba, ............... } over the alphabet ∑ = {a, b} 27
  • 28. Exercise 28 1. Let Σ = {a, b}.  Let L = { w ∈ Σ* | w contains at most one a }.  Which of the following is a regular expression for L? A. Σ*aΣ* B. b*ab* ∪ b* C. b*(a ∪ ε)b* D. b*a*b* ∪ b* E. b*(a* ∪ ε)b* F. None of the above, or two or more of the above. 2. Construct An NFA for the regular expression 1(11)*.