Professional Documents
Culture Documents
Lecture#3rd
By
Riaz Ahmad Ziar
r.ziar@kardan.edu.af
Regular Expression Practice Continue
• Write down the regular expression defined over Σ={a,b} where each string ends
with double a’s or double b’s.
• Write down the regular expression defined over Σ={a,b} Where each string start
with double b’s and end with double a’s.
• Write down the regular expression for the language defined over Σ={a,b} where
each string have exactly one double b’s.
• Write down the regular expression for the language defined over Σ={a,b} where
each string have exactly one triple a’s.
• Write down the regular expression defined over Σ={0,1} which consist of even
number of 0’s and even number of 1’s.
• Language defined over Σ={a,b} then write down regular expression for the
language where each string consist Odd numbers of a’s and b’s
Practice continue
• Construct a regular expression defining each of the following languages over the alphabet Σ = {a, b}
• All strings that end in double letter
• All strings that do not end in double letter
• All words that contain exactly two b’s or exactly three b’s, not more.
• Write down the regular expression for the language defined over Σ={a,b} that does
not contain aab
• Write RE of strings of a and b, which must end in triple b’s
• Write RE of strings of a and c followed by 3 b’s
• Write RE of strings of a and c, followed by any numbers of b’s
Practice Continue
• Find the shortest string that is in the language represented by the regular expression a*(ab)*b*.
• Find the shortest string that is not in the language represented by the regular expression
a*(ab)*b*.
• Consider the language S*, where S={a, b}
How many words this language have of length 2? of length 3?
Equivalent Regular Expression
• ϵ.R=R
• ϵ*=ϵ
• Φ*= ϵ
• R+R=R
• R*.R*=R* r=a* a*.a*=a*
• (R*)*=R* r=a* (a*)*=a*
• R+ Φ =R
• (ϵ+R)*=R*
• (R+R)S*=RS*
What is Regular language?
• The language generated by any regular expression is called a regular
language.
• It is to be noted that if R1, R2 are regular expressions, corresponding to the
languages L1 and L2 then the languages generated by
• If R1 = (aa+bb) and R2 = (a+b) then the language of strings generated by R1+R2, is also a
regular language, expressed by (aa+bb) + (a+b)
• If R1 = (aa+bb) and R2 = (a+b) then the language of strings generated by R1R2, is also a
regular language, expressed by (aa+bb)(a+b)
• If R = (aa+bb) then the language of strings generated by R*, is also a regular language,
expressed by (aa+bb)*
All finite languages are regular
• It is the fourth way of defining the language and can be defined as the collection of
the following.
• Finite number of states, having one initial and having none, one or many final
states.
• Finite set of input letters (Σ) from which input strings are formed.
• Finite set of transitions i.e. for each state and for each input letter there is a
transition showing how to move from one state to another.
It should be noted that for one language there may two or more FA’s which all be
correct but for a single FA there will be exactly one language.
Points to be noted
Formal Definition of FA
• Q: finite set of states
• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
Points to be noted
• It may be noted that to indicate the initial state an arrow head can also
be placed before that state and the final state can be indicated by
double circle. It is also to be noted while expressing the FA by its
transition diagram the labels of states are not necessary.
Example
Σ = {a,b}
States: x, y, z where x is an initial state and z is final state.
Transitions:
1. At state x reading a, go to state z
2. At state x reading b, go to state y
3. At state y reading a, b go to state y
4. At state z reading a, b go to state z
Con’t
• These transition can be expressed by the table called transition table as
under:
Con’t
• The finite state machine or transition diagram will be as under:
The above transition diagram is an FA accepting the language of strings, defined over
Σ = {a, b}, starting with a.
It may be noted that this language may be expressed by the regular expression a(a + b)*