Regular-Expression

Question 1

Which one of the following regular expressions represents the set of all binary strings with an odd number of 1’s?

A
10*(0*10*10*)*
B
((0 + 1)*1(0 + 1)*1)*10*
C
(0*10*10*)*10*
D
(0*10*10*)*0*1
Question 1 Explanation: 
The regular expression 10*(0*10*10*)* always generate string begin with 1 and thus does not generate string “01110” hence wrong option.
The regular expression ((0+1)*1(0+1)*1)*10* generate string “11110” which is not having odd number of 1’s , hence wrong option.
The regular expression (0*10*10*)10* is not a generating string “01”. Hence this is also wrong . It seems none of them is correct.
NOTE: Option 3 is most appropriate option as it generates the max number of strings with odd 1’s.
But option 3 is not generating odd strings. So, still it is not completely correct.
The regular expression (0*10*10*)*0*1 always generates all string ends with “1” and thus does not generate string “01110” hence wrong option.
Question 2

(a) An identifier in a programming language consists of upto six letters and digits of which the first character must be a letter. Derive a regular expression for the identifier.

(b) Build an LL(1) parsing table for the language defined by the LL(1) grammar with productions

Program → begin d semi X end
X → d semi X | sY
Y → semi s Y | ε 
A
Theory Explanation.
Question 3
Which of the following regular expressions represent(s) the set of all binary numbers that are divisible by three? Assume that the string ∊ is divisible by three.
A
(0+1 (01*0)*1)*
B
(0+11+10(1+00)*01)*
C
(0*(1(01*0)*1)*)*
D
(0+11+11(1+00)*00)*
Question 3 Explanation: 

Transition table

 

 

0

1

->*q0

q0

q1

q1

q2

q0

q2

q1

q2

 

DFA of divisible by 3

The regular expression will be

Three paths to reach to final state from initial state

Path 1: self loop of 0 on q0

Path 2: q0->q1->q0  hence 11

Path 3: q0->q1->q2->q1->q0 hence 10(1+00)*01

So finally the regular expression will be

(0+11+10(1+00)*01)*



Other regular expression is (if we consider two paths)

Path 1: Path 1: self loop of 0 on q0

Path 2: q0->q1->q2*->q1->q0 

Hence regular expression

(0+1 (01*0)*1)*

 

Another regular expression is (if we consider only one path and remaining part is present inside this path as cycles)

q0->q1->q2->q1->q0

Another regular expression is

(0*(1(01*0)*1)*)*

 

So A,B, C are correct.

Option D generates string 11100 which is not accepted by FA hence wrong.

Question 4
Which one of the following regular expressions correctly represents the language of the finite automaton given below?
A
ab*bab* + ba*aba*
B
(ab*b)*ab* + (ba*a)*ba*
C
(ab*b + ba*a)* (a* + b*)
D
(ba*a + ab*b)* (ab* + ba*)
Question 4 Explanation: 
Regular expression ab*bab* +ba*aba* does not generate the string “abb” which is accepted by FA hence this is not true.
(ab*b)*ab*+(ba*a)*ba* does not generate the string “abbaa” hence this is also wrong.
(ab*b+ba*a)*(a*+b*) generates epsilon hence this is also wrong.
(ab*b+ba*a)*(ab*+ba*) is the correct regular expression.
GATE 2022 Computer Science and Information Technology (CS)
Question 5
Consider the Deterministic Finite-state Automaton (DFA) A shown below. The DFA runs on the alphabet {0, 1}, and has the set of states {s, p, q, r}, with s being the start state and p being the only final state.

Which one of the following regular expressions correctly describes the language accepted by A?
A
1(0*11)*
B
0(0 + 1)*
C
1(0 + 11)*
D
1(110*)*
Question 5 Explanation: 
From the given DFA diagram, it clearly shows that there is no outgoing edge from node “r” so Regular expression won’t start with “0” , Option -B eliminated.
Starting state is "s" and Final state is "p".
There are two outgoing edges from the state "p".
one edge from state "p" to itself with alphabet “0” and another from State "p" to "q” and "q" to "p" with alphabet “1”
So most suitable answer is option C
Question 6
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:
letter → [A-Za-z]
digit → [0-9]
id → letter (letter | digit)*
Which one of the following Non-deterministic Finite-state Automata with - transitions accepts the set of valid identifiers? (A double-circle denotes a final state)
A
A
B
B
C
C
D
D
Question 7
Let L be the language on A={a,b,c} which consists of all words of the form w=ar bs ct where r,s,t>0. Which of the following is the valid regular expression ‘r’ such that L=L(r)?
A
r= a*b*c
B
r= aa*bb*c
C
r= aa*b*cc
D
r= aa*bb*cc*
Question 7 Explanation: 
→From the given question, w=ar bs ct where r,s,t>0 which means that the minimum value is r=s=t=1,
→Substitute in r=s=t=1 in w then L= abc
→So option D gives the regular expression abc
Question 8
Consider the following grammar:
S → Ax |By
A → By|Cw
B → x|Bw
C → y 
Which of the regular expressions describes the same set of strings as the grammar?
A
xw+y+xw*yx+ywx
B
xwy+xw*xy*ywx
C
xw*y+xw*yx+ywx
D
xwxy+xww*yywx
Question 8 Explanation: 
Option A do not contain xy which is generated by the grammar.
Option B do not contain xy which is generated by the grammar.
Option C do not contain xy which is generated by the grammar.
Question 9
Let a and b be the regular expressions, then (a*∪b*)* is not equivalent to
A
(a∪b)*
B
(b*∪a*)*
C
(b∪a)*
D
(a∪b)
Question 9 Explanation: 
The given regular expression is not equal to option D.
Question 10
The regular expression corresponding to the language L where L = { x ε {0, 1}*|x ends with 1 and does not contain substring 00 } is:
A
(1 + 01) * (10 + 01)
B
(1 + 01) * 01
C
(1 + 01) * (1 + 01)
D
(10 + 01) * 01
Question 10 Explanation: 
L = { 1, 01, 11, 111, 001, ............}
Option(A) is not correct because it can generate “10” which is not ending with “1”.
Option(B): It can’t generate “1” which is a string belongs to given language L. So it is not a correct option.
Option(C) : It is the correct option because it can generate all the strings generated by a given language.
Option(D): It is not the correct answer because it can’t generate strings like 1,11,........
Question 11
A
Only (i) is false
B
Only (ii) is false
C
Only (iii) is false
D
Both (i) and (iii) are false
E
None of the above
Question 12
Consider the following regular expressions: a) r=a(b+a)* b) s=a(a+b)* c) t=aa*b Choose the correct answer from the options given below based on the relation between the languages generated by the regular expressions above:
A
L(r)⊆L(s)⊆L(t)
B
L(r)⊇L(s)⊇L(t)
C
L(r)⊇L(t)⊇L(s)
D
L(s)⊇L(t)⊇L(r)
Question 12 Explanation: 
r={a,aa,ab,aaa,aab,aba,aaab,......}
s={aa,ab,aaa,aab,aba,aaab,......}
t={ab,aab,aaab,....}
If you notice then r⊇s⊇t
Question 13
Let L1 and L2 be languages over Σ =(a,b) represented by the regular expressions (a* + b)* and (a+b)* respectively. Which of the following is true with respect to the two languages?
A
L1 ⊂ L2
B
L2 ⊂ L1
C
L1 = L2
D
L1 ∩ L2 = ɸ
Question 13 Explanation: 
(a+b)* is a universal set which can generate all the strings possible over the alphabet “a” and “b”.
(a+b)* = (a* +b)*= (a+b*)=(a*b*)*= (a* +b*)*= a*(ba*)*=b*(ab*)*
There are 13 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access