0% found this document useful (0 votes)
31 views26 pages

Unit 2 - (Regular Language

Chapter on Theory of Computation

Uploaded by

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

Unit 2 - (Regular Language

Chapter on Theory of Computation

Uploaded by

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

Theory of Computation

Dr. Sushil Kumar Azad

Faculty
School of Engineering & Technology(SOET)
K. R. Mangalam University

Unit 2
Regular Expression
Objective

This unit is designed to enable you to:


 State precisely what it means for a problem to be computable,
and show that some problems are not computable
 State precisely what it means to reduce one problem to
another, and construct reductions for simplest examples
 Classify problems into appropriate complexity classes, and use
this information effectively
Unit 2- Overview

 Session 15: Equivalence of DFA and NFA

 Session 16: Finite State Machines, Mealy Machines

 Session 17: Moore Machines, Conversion from Mealy to


Moore

 Session 18: Conversion from Moore to Mealy

 Session 19: Regular Language and Regular Expression


Sessions Overview

 Session 20: Construction of Finite Automata from Regular


Expression
 Session 21: Construction of Regular Grammer from Finite
Automata
 Session 22: Construction of Finite Automata from Regular
Grammer
 Session 23: Pumping Lemma and Myhill Nerode Theorem
Session XX

Regular Language
Session Outlook

1. Regular Language (or Regular Set)


2. Closure Properties of regular language
3. Regular Expression
4. Regular Expression VS Regular Language
5. Properties of regular expression
6. Rules of regular expression
7. Practice Questions
Learning Outcomes

• Understand the fundamental concepts of regular language.


• Apply knowledge of regular language to represent them in
various forms.
• Remember the basic definition and purpose of regular
language and closure properties.
• Analyze the trade-offs between regular language and regular
expression.
Regular set

. Definition : A regular set over  is any set that can be obtained by the finite

applications of the following rules:

1. {a} is a regular set , for all a

2. {} =  , an empty set is a regular set

3. {  } is a regular set

4. If L1 and L are regular set, then so is L  L


2 1 2

5.If L and L are regular sets then so is L L


1 2 1 2

If L is a regular set, then so is L*.


.
Let  = {0,1}. The following are some valid regular sets:

{0} , {1}

{0}{1},

{0}.{1}{0,1},

{0}*,

{}*
Definition : A regular expression over  is a sequence of symbols obtained by the

finite applications of the following rules:

1. a is a regular expression, representing the set {a} for all a

2. The symbols  and  are regular expressions, representing the sets {} and {}
respectively.

3. The expressions r1 . r2 , r1 + r2 and r1* are regular expressions,

if r and r are regular expressions, representing the sets


1 2

(r ), L(r ), L(r )  L( r ) and L(r )* , respectively.


1 2 1 2 1
What are regular expressions?

 The regular expression is a compact and symbolic representation to describe a

set of language in the form of a finite string of symbols.

 Not every language can be represented as a regular expression. The language

that can be represented as a regular expression is a regular language.

 The regular expressions are nothing but a common shorthand notation to

represent such sets.

 There is a one-one correspondence between the set of regular languages and

regular expressions.
.
.

Let  = {0,1}, then the following are regular expressions:

(i) 0 + 1 - represents the set {0, 1}.

(ii) 0.(0 + 1) – represents the set { 00, 01}.

(iii) ((0 + ).1* ) - represents the set

{ , 1, 11, 111, …., 0, 01, 0111, ….}.


Test your Knowledge:

Find the regular expression representing the following sets:


.
(i) The set of all strings over {a,b} with three consecutive b’s

(a+b)*bbb(a+b)*

(ii) The set of all strings over {a, b} in which there are at least two occurrences of b

between and two occurrences of a.

b* + (b + abb)*ab*

(iii) the language of all words with an odd number of b’s

a*b(a*ba*b)*a*

(v) Set of all strings over {0, 1} having atmost one pair of 0’s or atmost
Regular Expression vs Regular Language

• The symbols of the regular expressions are distinct from


those of the languages. These symbols are given below −
.Equivalent Regular Expressions

Two regular expressions r and r are said to be equivalent if


1 2

the languages represented by them are equal,

i.e., if L(r ) = L( r ).
1 2
Properties of Regular Expression
•It is a way of representing regular languages.

•The algebraic description for regular languages is done using


regular expressions.

•They can define the same language that various forms of finite
automata can describe.

•Regular expressions offer something that finite automata do not,


i.e. it is a declarative way to express the strings that we want to
accept. They act as input for many systems. They are used for
string matching in many systems(Java, python etc.)

•For example, Lexical-analyzer generators, such as Lex or Flex.


Practice Questions

1. Write a regular expression for the language of C identifiers.


2. Write a regular expression for the language
L = {abnw: n >= 3, w є (a + b)+}
3. Write a regular expression for a set of strings of 0s and 1s
with even number of 0s.
4. Write the regular expression for the language starting and
ending with a and having any having any combination of b's
in between.
5. Write the regular expression for the language starting with a
but not having consecutive b's.
Review

• In this session we have discussed-


• Regular Language and Closure Properties of regular
language
• Regular Expression
• Difference between Regular Expression and Regular
Language
• Properties and rules of regular expression
Test Yourself

1.Which of the following statements about regular languages is


true?
A) Regular languages can be recognized by pushdown automata.
B) Regular languages can be recognized by Turing machines.
C) Regular languages can be recognized by finite automata.
D) Regular languages can contain nested structures.

2. Which of the following operations is NOT closed under regular


languages?
E) Union
F) Intersection
G) Complementation
H) Division
Test Yourself

3. Which of the following regular expressions matches the


language containing strings of any length composed of only the
characters 'a' and 'b’?
A) (𝑎∣𝑏)∗(a∣b)∗
B) (𝑎𝑏)∗(ab)∗
C) (𝑎+𝑏)∗(a+b)∗
D) (𝑎∗𝑏∗)∗(a∗b∗)∗

4. What is the Kleene closure of the language containing only the


string "101"?
E) {101}{101}
F) {1,0,101}{1,0,101}
G) {101,101101,101101101,...}{101,101101,101101101,...}
H) {𝜖}{ϵ}
Test Yourself

5. Which of the following is a regular expression that describes


a language containing an even number of 0s followed by an odd
number of 1s?
A) (00)∗(1(11)∗1)∗(00)∗(1(11)∗1)∗
B) (00)∗(1(11)∗)∗(00)∗(1(11)∗)∗
C) (00)∗(1(11)∗1)(00)∗(1(11)∗1)
D) (0(00)∗1)∗(11)∗(0(00)∗1)∗(11)∗
Gate Questions
1. S –> aSa| bSb| a| b ;The language generated by the above grammar over the
alphabet {a,b} is the set of

(A) All palindromes.


(B) All odd length palindromes.
(C) Strings that begin and end with the same symbol
(D) All even length palindromes.

Answer (B)
The strings accepted by language are {a, b, aaa, bbb, aba, bab, ..}. All of these strings are
odd length palindromes.

2. Which one of the following languages over the alphabet {0,1} is described by the
regular expression: (0+1)*0(0+1)*0(0+1)*?

(A) The set of all strings containing the substring 00.


Gate Questions
(B)The set of all strings containing at most two 0’s.
(C)The set of all strings containing at least two 0’s.
(D)The set of all strings that begin and end with either 0 or 1.

Answer (C)
The regular expression has two 0’s surrounded by (0+1)* which
means accepted strings must have at least 2 0’s.

3. Which one of the following is FALSE?

(A) There is unique minimal DFA for every regular language


(B) Every NFA can be converted to an equivalent PDA.
(C) Complement of every context-free language is recursive.
(D) Every nondeterministic PDA can be converted to an equivalent
deterministic PDA.
Gate Questions
Answer (D)

Deterministic PDA cannot handle languages or grammars with


ambiguity, but NDPDA can handle languages with ambiguity and
any context-free grammar. So every nondeterministic PDA can not
be converted to an equivalent deterministic PDA.

4. Let L = L1 ∩ L2, where L1 and L2 are languages as defined


below:
L1 = {ambmcanbn | m, n >= 0 }
L2 = {aibjck | i, j, k >= 0 }
Then L is
(A) Not recursive
(B) Regular
(C) Context free but not regular
Support Material references

Youtube Channels
• Theory of Computation THE GATEHUB
https://www.youtube.com/watch?v=p1oqDS0fayc&list=PL1QH9gyQXfgsUBfYUR0W
irJASgif4pHVX&index=1

• Theory of Computation by Easy Engineering Classes


https://www.youtube.com/watch?v=iD6u_2iNnu0

• Mod-01 Lec-01 What is theory of computation?nptelhrd


https://www.youtube.com/watch?v=al4AK6ruRek
?

You might also like