You are on page 1of 38

Lecture 04 –Regular Expression & Transition Graphs

(Dr. Nida Aslam)


• Basics of TG
• Basics for conversion of FA  RE
• Rules for conversion of FA  RE
• Kleen’s Theorem
• Examples
2/9/2024
Conversion of RE FA
 Automata: It’s an abstract machine, that will accept RE

 Finite Automata: Finite number of states, exactly one of them will be the initial state, zero
or more will be final state.

 For every RE there exist at least one FA and for every FA there exist at least one RE.

 So, they are interchangeable

 Now we will see how to construct FA for a given RE.

Dr. Irfan 2/9/2024 2


Conversion of RE  FA
 Basics for conversion of RE FA

1. ʰФ
É É
I 2. a

sse I
a

yyffIfÉ
Is
a

3 There3. a + one
showbe b finalstate a,b

2 b 4 byone
Eliminatethestates one

anda excepttheinitialandthefinal
4. a . b sa a b
node

Dr. Irfan 2/11/2024 3


Conversion of RE  FA
 Basics for conversion of RE FA
empty
1. Ф

2. a a

or
3. a + b a,b

and
4. a . b a b

Dr. Irfan 2/11/2024 3


Conversion of RE  FA
 Basics for conversion of RE  FA
a
5. a* 1 a aa aaa

b
a
a ab abb
6. ab*
a
n ab abab ababab
7. (ab)* b
a

b
b n ab ba abbabaab abbaabba
8. (ab + ba)* a

Dr. Irfan 2/11/2024 4


Transition Graphs (TGs)
 It is the most generalized automata to describe a RE

 It may have a complete RE or its subset at transition

 Very easy to construct and used to convert FA to RE.

 Definition: A transition graph, abbreviated TG, is a collection of three things:

1. A finite set of states at least one of which is designated as the start state (→) and some (maybe

none) of which are designated as final states (*).

2. An alphabet ∑ of possible input letters from which input strings are formed.

3. A finite set of transitions that show how to go from one state to another based on reading

specified substrings of input letters (possibly even the null string л ).

Dr. Irfan 2/11/2024 5


Examples

ab a b aba
aa bb ab ba

Eaab
Dr. Irfan 2/11/2024 6
Examples
a,b
a,b
a a

ab
ab a,b

a
a

b
b

a,b
ab
Dr. Irfan 2/11/2024 7
Kleen’s Theorem
 Any language that can be defined by
 regular expression
 or finite automaton
 or transition graphII A

 can be defined by all three methods.

 This theorem is the most important and fundamental result in the Theory of Finite
Automata.

 Every FA is a TG by default while every TG may or may not be an FA.

 Now we will go for conversion from FA to TG to RE.

Dr. Irfan 2/11/2024 8


FA to RE
 The proof of this part will be by a constructive algorithm.

 This means that we present a procedure that starts out with an FA, transition graph and
ends up with a regular expression that defines the same language.

 TG is an intermediate state when we convert FA to RE.

 Because during conversion, FA becomes TG and is no more an FA.


 For instance, we can have more than one initial state.
 A string can be used as a transition etc.

 So, instead of calling it FA, we call it TG.


 Means a graph for the transition from FA to RE.

Dr. Irfan 2/11/2024 9


Rule for FA to RE
 Rules for conversion of FA  RE

1. The initial state should not have incoming edges/arrows

є
Converted to

2. The final state should have no outgoing edges/arrows

THE
Converted to
є

Dr. Irfan 2/11/2024 10


Rule for FA to RE
 Rules for conversion of FA  RE

3. The final state should be one (if there’s exist more than one final state, should be reduced to
one)

+ є

Converted to
є +
+
є
+

Dr. Irfan 2/11/2024 11


Rule for FA RE
 Rules for conversion of FA RE

State Elimination: Remove states 1 by 1 (other than the initial and final state) and you will
get target RE.
Example:
a,b,c
+

OR RE = a + b + c
a+b+c
+

Example:

ab
+ RE = ab

Dr. Irfan 2/11/2024 12


Example
State Elimination: Remove states 1 by 1 (other than the initial and final state) and you will get
target RE.
Example:

Dr. Irfan 2/11/2024 13


Conversion of FA RE
Example: Convert the FA in the below Figure into RE?

Removing “B” the path must be the same

ab*c
+

Regular Expression will be

RE = ab*c

Dr. Irfan 2/11/2024 14


Conversion of FA RE
Example: Convert the FA in the below Figure into RE?

are i

ii In
r.I.rs m ryo.rs nra lrs rutrs

a b C
= 𝑟 𝑟∗ 𝑟 + 𝑟 𝑟∗ 𝑟 + 𝑟 𝑟 𝑟 ∗

= 𝑟 𝑟 ∗ (𝑟 + 𝑟 + 𝑟 )
Dr. Irfan 2/11/2024 15
Examples
Example: Convert the FA in the below Figure into RE?

= 𝒂𝒃𝒂∗ ba+ 𝒂𝒃𝒂∗ b+ 𝒃𝒃𝒃𝒂∗ b+ 𝒃𝒃𝒃𝒂∗ ba


= 𝒂𝒃𝒂∗ (ba+ b) + 𝒃𝒃𝒃𝒂∗ (b+ ba)

Dr. Irfan 2/11/2024 16


Example
Example: Convert the FA in the below Figure into RE?
Caabb a b Caab

Dr. Irfan 2/11/2024 17


Example

Dr. Irfan 2/11/2024 18


Example

Dr. Irfan 2/11/2024 19


Example
Example: Convert the FA in the below Figure into RE?

Dr. Irfan 2/11/2024 20


Example

Dr. Irfan 2/11/2024 21


Example

Dr. Irfan 2/11/2024 22


Example

= [ 𝐚𝐚 + 𝐛𝐛 + (𝐚𝐛 + 𝐛𝐚)(𝒂𝒂 + 𝒃𝒃)∗ (𝒂𝒃 + 𝒃𝒂)]∗

Dr. Irfan 2/11/2024 23


Example

affiliation

ME
i iñ i
butcanbal
can
Iffarabas
fffht
i
Dr. Irfan 2/11/2024 19
Conversion of FA RE
Example: Example:

b 2
+
0 a c
I
IN
A B
1
y +
d
µ
+

A B b

A B y y s L IN
sM

s 0 13 s Y paths
as y IN
010T y
albted
µ
Dr. Irfan 2/11/2024 24
Conversion of FA RE
Example: c
b
d +
A B C
C
a

A d sc

s b 13 d e

b
13 d e

blatant'd
s c
Dr. Irfan 2/11/2024 25
Conversion of FA RE
Example: c d
a
A B
we b

if Bd c y if p.de y

act
n e
s s u s ta 1 e
g y
u

ac 1 c y a I
actdtab't cadtbeat
y Dr. Irfan y 2/11/2024 26
Conversion of FA  RE
do Example: 0 0
1
A B
1
s no
A B

j
10
s A g y
u
o

s 11 0 y
Dr. Irfan 2/11/2024 27
Conversion of FA  RE
Example:
0 0
0
1 1
A B C

I 0 0 0 1 3

is remove a y
4101
y u
2 611041 y
Remove B s cÑ

y Dr. Irfan 2/11/2024 28


Conversion of FA  RE
do  Define RE for FA = b
b
a
A B
a

5 a B e
sy
b
bra e
s s y

sea e g

balbtabt.at
y Dr. Irfan 2/11/2024 29
Conversion of FA  RE
do  Define RE for FA = b Accept EVEN
b numbers of a’s
a
A B
a
b

if p
yᵗ
s a
say
fara
A s Y
btabt.at
s y Dr. Irfan 2/11/2024 30
Conversion of FA  RE
 Define RE for FA = b should be END
do b with a.
a

A b B

5 B e
sy

bra BÑ e
s g y
Ubra
pinnate
bra y

b.albtbb.at
s y
Dr. Irfan 2/11/2024 31
Convert FA to RE (Solve)

Dr. Irfan 2/11/2024 32


End of Lecture - 04
Any questions?

2/9/2024 33

You might also like