Chapter Three - RE
Chapter Three - RE
Campus
Department of Computer
Automata and complexity
Science
theory
*
• L = Zero or More Occurrences of a = a*
𝜖
a
aa
aaa Infinite …..
aaaa
aaaaa….
.
+
• L = One or More Occurrences of a = a+
a
aa
aaa Infinite …..
aaaa
aaaaa…..
Regular
5.𝐒𝐭𝐫𝐢𝐧𝐠𝐬 expression
: 𝐚𝐛𝐜 , 𝐛𝐜𝐚 , 𝐛𝐛𝐛 ,𝐜𝐚𝐛 ,𝐚𝐛𝐚over
…. that represent all string of length 3.
𝐑 . 𝐄 .= ( 𝐚|𝐛|𝐜 )( 𝐚|𝐛|𝐜 ) (𝐚|𝐛|𝐜)
6. All:𝟎,𝟏𝟏,𝟏𝟎𝟏,𝟏𝟎𝟏𝟎𝟏,𝟏𝟏𝟏𝟏…
𝐒𝐭𝐫𝐢𝐧𝐠𝐬 binary string +
𝑹.𝑬.=( 𝟎 𝟏 )(and
17.…All binary string with at least 3 characters rd | |
𝟎 𝟏) 3𝟎(𝟎∨𝟏)∗
character should be zero
𝑹. 𝑬 .=𝒂∗𝒃 𝒂∗𝒃𝒂∗
… Language which consist of exactly two b’s over the set
18.
1 and( 𝟎∨𝟏
…. Length of string should be at least𝑹.𝑬.=
23. | |
) ( 𝟎∨𝟏3 )( 𝟎∨𝟏) ( 𝟎∨𝟏)( 𝟎∨𝟏 )( 𝟎∨𝟏)
at most
∗ ∗ ∗ ∗ ∗
…. 24. No. of zero should be multiple of 3 𝑹. 𝑬 .=(𝟏 𝟎𝟏 𝟎𝟏 𝟎𝟏 )
Mekonen M. # CoSc3071 Unit 3 – Regular Expression 10
Regular expression examples
25. The language with where should be multiple of 3
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝒂𝒂𝒂,𝒃𝒂𝒂𝒂,𝒃𝒂𝒄𝒂𝒃𝒂,𝒂𝒂𝒂𝒂𝒂𝒂.. ∗ ∗ ∗
𝑹.𝑬.=( ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) 𝒂 ( 𝒃∨𝒄 ) )
∗∗
∗
30. 𝑹. 𝑬 .=𝟏(𝟎∨𝟏)(( 𝟎|𝟏 ) (𝟎∨𝟏))
….String start with 1 and has even length
𝑺𝒕𝒓𝒊𝒏𝒈𝒔:𝟎𝟎𝟏𝟎𝟏,𝟏𝟎𝟏𝟎𝟎,
31. All string begins𝟏𝟏𝟎,𝟎𝟏𝟎𝟏𝟏… 𝑹.𝑬.=(𝟎𝟎∨𝟏𝟏)(𝟎∨𝟏)∗∨( 𝟎|𝟏 ) ∗(𝟎𝟎∨𝟏𝟏)
or ends with 00 or 11
L={ }=
start
start L = {e}
Ms e
start e L = {L(Ms) L(Mt)}
i f
e
Mt e
start
i e Ms e Mt e f
start a
a
start b
b
start b a
ba
a
e
e
(a|b) start
e b
e
a
e
e e
e
(a|b)*
e b e
step 1:
𝑞0 𝑞1
(a|b)* ba
𝑞3
step 2:
𝑞2 a
𝑞4
𝑞 0 𝑞1 𝑞6
𝑞7
b
𝑞8 a
𝑞
𝑞9
9
𝑞3 b
𝑞5
a
A
b
𝐶 b
D
b
a
Exercise 1:
1. Give an NFA that accepts the
language L((a+b)*b(a+bb)*)
start b a
q1 q2 q3
q1
q2 qi q1 q2
Step 1:Thumb Rule: There must exist only one final state in the DFA.
If there exists multiple final states in the DFA, then convert all the final states into non-final
states and create a new single final state.
q2
q2 q1 qqf2
q1
q3
q3
Mekonen M. # CoSc3071 Unit 3 – Regular Expression 28
FA to Regular Expression – State Elimination
Step 3:Thumb Rule: The final state of the DFA must not have any outgoing
edge.
If there exists any outgoing edge from the final state, then create a new final state having no
outgoing edge from it.
q1 q2 q3
q1 q2 q3
Step 4.
Eliminate all the intermediate states one by one.
These states may be eliminated in any order.
In the end,
Only an initial state going to the final state will be left.
The cost of this transition is the required regular expression.
Exercise:
The grammar G = ({S, A, B}, {a, b},S, P) with production
SA
AaB | λ
BbA
Is left-linear or right-linear?
a
q1 q2 q1
a
q2
Regular Expressions
DFA or NFA
Regular Grammars