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?
10*(0*10*10*)*
| |
((0 + 1)*1(0 + 1)*1)*10*
| |
(0*10*10*)*10* | |
(0*10*10*)*0*1
|
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 | ε
Theory Explanation. |
Question 3 |
(0+1 (01*0)*1)* | |
(0+11+10(1+00)*01)* | |
(0*(1(01*0)*1)*)* | |
(0+11+11(1+00)*00)* |
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 |
ab*bab* + ba*aba* | |
(ab*b)*ab* + (ba*a)*ba* | |
(ab*b + ba*a)* (a* + b*) | |
(ba*a + ab*b)* (ab* + ba*) |
(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 |
Which one of the following regular expressions correctly describes the language accepted by A?
1(0*11)* | |
0(0 + 1)* | |
1(0 + 11)* | |
1(110*)* |
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 |
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 | |
B | |
C | |
D |
Question 7 |
r= a*b*c | |
r= aa*bb*c | |
r= aa*b*cc | |
r= aa*bb*cc* |
→Substitute in r=s=t=1 in w then L= abc
→So option D gives the regular expression abc
Question 8 |
S → Ax |By A → By|Cw B → x|Bw C → yWhich of the regular expressions describes the same set of strings as the grammar?
xw+y+xw*yx+ywx | |
xwy+xw*xy*ywx
| |
xw*y+xw*yx+ywx | |
xwxy+xww*yywx |
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 |
(a∪b)* | |
(b*∪a*)* | |
(b∪a)* | |
(a∪b) |
Question 10 |
(1 + 01) * (10 + 01) | |
(1 + 01) * 01 | |
(1 + 01) * (1 + 01) | |
(10 + 01) * 01 |
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 |
Only (i) is false | |
Only (ii) is false | |
Only (iii) is false | |
Both (i) and (iii) are false | |
None of the above |
Question 12 |
L(r)⊆L(s)⊆L(t) | |
L(r)⊇L(s)⊇L(t) | |
L(r)⊇L(t)⊇L(s) | |
L(s)⊇L(t)⊇L(r) |
s={aa,ab,aaa,aab,aba,aaab,......}
t={ab,aab,aaab,....}
If you notice then r⊇s⊇t
Question 13 |
L1 ⊂ L2 | |
L2 ⊂ L1 | |
L1 = L2 | |
L1 ∩ L2 = ɸ |
(a+b)* = (a* +b)*= (a+b*)=(a*b*)*= (a* +b*)*= a*(ba*)*=b*(ab*)*