1
9/9/2024
Sri Raghavendra Educational Institutions Society (R)
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
Sri Krishna Institute of Technology
www.skit.org.in
Department of Computer Science & Engineering
SUBJECT CODE:BCS503
SUBJECT NAME:THEORY OF COMPUTATION
Regular Expressions
2
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Regular Expressions vs. Finite Automata
< input: string , output: [accept/reject] >
3
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Regular Expressions
4
Regular �expressions
Finite Automata�(DFA, NFA, ε-NFA)
Regular�Languages
=
Automata/machines
Syntactical �expressions
Formal language �classes
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Language Operators
5
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Kleene Closure (the * operator)
Example:
6
“i” here refers to how many strings to concatenate from the parent language L to produce strings in the language Li
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Kleene Closure (special notes)
Σ* denotes the set of all words over an alphabet Σ
7
Why?
Why?
Why?
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Building Regular Expressions
8
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Example: how to use these regular expression properties and language operators?
9
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Precedence of Operators
10
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Finite Automata (FA) & Regular Expressions (Reg Ex)
11
ε -NFA
NFA
DFA
Reg Ex
Theorem 2
Theorem 1
Proofs �in the book
Kleene Theorem
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
DFA to RE construction
12
Reg Ex
DFA
Theorem 1
Example:
q0
q1
q2
0
1
1
0
0,1
(1*)
0
(0*)
1
(0 + 1)*
Informally, trace all distinct paths (traversing cycles only once) � from the start state to each of the final states � and enumerate all the expressions along the way
1*00*1(0+1)*
00*
1*
1
(0+1)*
Q) What is the language?
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
RE to ε-NFA construction
13
ε -NFA
Reg Ex
Theorem 2
Example:
(0+1)*01(0+1)*
0
1
ε
ε
ε
ε
ε
ε
ε
0
1
0
1
ε
ε
ε
ε
ε
ε
(0+1)*
01
(0+1)*
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Algebraic Laws of Regular Expressions
14
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Algebraic Laws…
15
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
True or False?
Let R and S be two regular expressions. Then:
16
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
Summary
17
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in