0% found this document useful (0 votes)
47 views24 pages

Unit-2 Regular Expressions - (Part 1)

The document discusses the theory of computation, specifically focusing on regular expressions and their applications in various data processing tasks such as pattern matching and data validation. It includes definitions of regular sets, examples of regular expressions, and the application of Arden's Theorem for constructing regular expressions from automata. Additionally, it outlines algebraic methods for solving equations related to deterministic finite automata (DFA).

Uploaded by

ssnviit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views24 pages

Unit-2 Regular Expressions - (Part 1)

The document discusses the theory of computation, specifically focusing on regular expressions and their applications in various data processing tasks such as pattern matching and data validation. It includes definitions of regular sets, examples of regular expressions, and the application of Arden's Theorem for constructing regular expressions from automata. Additionally, it outlines algebraic methods for solving equations related to deterministic finite automata (DFA).

Uploaded by

ssnviit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIT-II

Subject-Theory of Computation

Prof. Shweta Tiwaskar


[email protected]
Department of Computer Engineering

BRACT’S, Vishwakarma Institute of Information Technology, Pune-48


(An Autonomous Institute affiliated to Savitribai Phule Pune University)
(NBA and NAAC accredited, ISO 9001:2015 certified)

1
Regular Expression

2
• Regular Set: Any set represented by a regular expression is called regular
set

3
Application of Regular Expression(RE)
• RE are useful for numerous practical day to day tasks that a data scientist
encounters. They are used everywhere
• wide variety of text /data processing tasks
• natural language processing
• pattern matching
• Data validation
• Data scraping (especially web scraping)
• Data extraction
• Simple parsing, the production of syntax highlighting systems, and many
other tasks.

4
Regular Expression Regular Set
a {a}
(a+b) {a,b}
ab {ab}
a* { , a, aa, aaa, aaaa,………}
a+ or a(a)* {a, aa, aaa, aaaa,………}
(0+1)* { null, 0,1,01,10,11,00,……}
(a+b)* {null,a,b,ab,aa,bb,ba,….}
(a+b)* ab {ab,aab,bab,aab,…..}
(aa)* {null,aa,aaaa,aaaaaa……}
(0*10*) { 1,01,10, 010,00100 ,….. }
(aa)*(bb)*b { b, aab, bbb, aabbb…… }
(aa + ab + ba + bb)* { null, aa,ab,ba,bb,aaab,……. }
(0+€) (1+€) { null,0,1,01 }
(0+10*) {0, 1,10,100,1000…….}
5
Regular SET Regular Expression
{101} 101
{abba} abba
{01,10} 01+10
{ ,ab}
{1,11,111,1111,……..}

6
{00,000,100,0000,1100…..}
a) Answer: (0+1) 00

{01,001,010,……..}
B) Answer:0 (0+1) 1

7
Answer=(1+011)*

8
Answers:
1: (a+b)* bbb (a+b)*
2. 00 (0+1)*
3. 1(0+1)*00

9
Identities for Regular Expression

10
Identities for Regular Expression

11
12
HW

13
14
15
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*
• Proof −
• R = Q + RP
R = Q + (Q + RP)P [After putting the value R = Q + RP]
R= Q + QP + RPP
When we put the value of R recursively again and again, we get the following
equa on −
R = Q + QP + QP2 + QP3…..
R = Q (ε + P + P2 + P3 + …. )
R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
Hence, proved.
16
Algebric Method Using Arden’s Theorem
• The transition graph does not have NULL moves.
• It has only one initial state ie. V1
• Vertices are V1….Vn.
• Rij represents the set of labels of edges from Vi to Vj, if no such edge
exists, then Rij =
• Step 1 − Create equa ons as the following form for all the states of
the DFA having n states with initial state V1.
V1 = V1R11 + V2R21 + … + VnRn1 + ε
V2 = V1R12 + V2R22 + … + VnRn2
…………………………
Vn = V1R1n + V2R2n + … + VnRnn
• Step 2 − Solve these equa ons to get the equa on for the final state
in terms of Rij
17
Construct a regular expression corresponding to the automata given below using Arden’s Theorem.

q1=q2b+q3a+null
q2=q1a
q3=q1b
q4=q2a+q3b+q4a+q4b

Put eq. q2 7 q3 in eq q1
q1= q1ab+q1ba+null
q1=q1(ab+ba)+null
R=Q=RP R=QP* R=q1, Q=null, P= (ab+ba)
q1=null (ab+ba)*= 18

(ab+ba)*---Answer
Construct a regular expression corresponding to the automata given below using Arden’s Theorem.

q1=q1(ab+ba)+˄
q1=q2b+q3 a+

q2=q1a R=Q+RP= QP*


q3=q1b R=q1, Q=null, P=(ab+ba)
q4=q2a+q3b+q4a+q4b q1=null(ab+ba)*
Put eq. of q2 and q3 in q1
q1=q1ab+q1ba+
q1=(ab+ba)*
19
HW

20
HW Solution

21
22
Construct a regular expression for the following diagram

23
24

You might also like