
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Construct Regular Expression for Given Languages
Problem 1
Write the regular expression for the language accepting all the strings containing any number of a's and b's.
Solution
The regular expression will be −
r.e. = (a + b)*
This will give the set as L = {E, a, aa, b,bb,ab,ba, aba, bab,.....},any combination of a and b.
The (a + b)* shows any combination with a and b even a null string.
Problem 2
Write the regular expression for the language starting with a but not having consecutive b's.
Solution
The regular expression has to be built for the language: L = {a, aba, aab, aba, aaa, abab, .....}
The regular expression for the above language is −
R = {a + ab}*
Problem 3
Write the regular expression for the language accepting all the string in which any number of a's is followed by any number of b's is followed by any number of e's.
Solution
As we know, any number of a's means a* any number of b's means b*, any number of e's means c*. Since as given in the problem statement, b's appear after a's and e's appear after b's. So the regular expression could be −
R = a* b* c*
Problem 4
Describe the language denoted by following regular expressions r.e. = (b* (aaa)* b*)*
Solution
The language can be predicted from the regular expression by finding the meaning of it. We will first split the regular expression as −
r.e .= (any combination of b's) (aaa)* (any combination of b's)
L = {The language consists of the string in which a's appear triples, there is no restriction on the number of b's}