Theory of Computation · Regular Expressions & Languages
50 questions, newest first
GATE CSE has asked 50 questions on Regular Expressions & Languages (Theory of Computation) from 1991 to 2025, in 31 of the 46 papers; the most recent is in GATE CSE 2025 Set 2. In the last five years it carried 1.4 marks per 100-mark paper on average, against 1.2 since 2003. Since 2014 the questions have been 10 MCQ, 3 MSQ and 3 NAT. 5 groups of questions here are solved the same way; “One per method” keeps the newest of each.
Over {a,b}, define L1={αβα | α∈{a,b}+ and β∈{a,b}+}, and L2={αβα | α∈{a}+ and β∈{a,b}+}. Both α and β must be nonempty. Which is correct? A both regular; B only L1 regular; C only L2 regular; D neither regular.
Your answer
Answer & solution
Official answer: C
Approach: Simplify L2 directly, then prove L1 nonregular using intersection with a carefully chosen regular language. Every L2 word begins and ends in a and has length at least three. Conversely any such word can use α=a and the nonempty intervening substring as β. Hence L2=a(a|b)+a, which is regular. For L1 intersect with R={abr aabs:r,s≥1}. R is regular. A word in R has exactly three a’s. If it equals αβα, the two disjoint copies of α cannot each contain two a’s; because α starts at the initial a, it contains exactly one a. It also ends in b, and its suffix copy must start at the third a: starting at the second a would include two a’s. Thus α=abs. This is a prefix exactly when r≥s. The remaining β=br−sa is nonempty. Therefore L1∩R={abr aabs:r≥s≥1}. If this intersection were regular with pumping length p, choose w=abp aabp. Any pumpable nonempty substring within the first p positions either includes the initial a or consists only of b’s from the first block. Pumping it down in the first case destroys the required initial a; in the second case it reduces r below s. Every permitted decomposition fails, contradicting the pumping lemma. Regular languages are closed under intersection, so L1 cannot be regular. L2 is regular and L1 is not: C. A repeated substring does not automatically prove nonregularity; the explicit restriction and pumping argument supply the proof.
Let #a(w),#b(w) count symbol occurrences. Which languages are regular? A. {a^m b^n:m,n≥0}. B. {a,b}* ∩ {a^m b^n c^(m−n):m≥n≥0}. C. {w∈{a,b}*: #a(w)≡2 (mod 7), #b(w)≡3 (mod 9)}. D. {w∈{a,b}*: #a(w)≡2 (mod 7), #a(w)=#b(w)}.
Select all that apply
Answer & solution
Official answer: A, C
A is described by the regular expression a*b*, so it is regular. The two block lengths are independent; there is no equality constraint to remember.
For B, membership in {a,b}* excludes every c. Hence m−n=0 and the intersection is exactly {an bn:n≥0}. This is nonregular: for a pumping length p, any allowed pumping segment in the initial a-block of ap bp changes the a-count without changing the b-count.
C needs only finite modular information. A DFA state (r,s) stores #a modulo 7 and #b modulo 9. On a update r to r+1 modulo 7; on b update s to s+1 modulo 9. Start at (0,0), accept (2,3). The 7·9=63-state construction proves regularity, without claiming a state-minimality result.
For D, intersect with the regular language a*b*. If D were regular, this intersection K={ak bk:k≡2 mod 7} would also be regular. Choose an allowed k greater than a proposed pumping length. Any pumping segment within the first p positions consists only of a's; pumping it changes one count and breaks equality. Thus K, and therefore D, is nonregular. A modular restriction alone is finite-state, but it does not eliminate an unbounded equality requirement. Select A,C.
Over {0,1}, r=0*+1* and s=01*+10*, where + means union and * means Kleene star. Count strings of length at most 5 that belong to neither language, including the empty string in the universe.
Answer & solution
Official answer: 44
Approach: Count all short binary strings, subtract the union of the two languages, and account for their overlap. 1. There are Σ from length 0 to 5 of 2^length =1+2+4+8+16+32=63 strings. The empty string is the single length-zero string. 2. Language r contains ε and, at each positive length 1–5, the all-zero and all-one strings. Thus |r within the limit|=1+2×5=11. Count ε only once even though both starred expressions generate it. 3. Language s contains a leading 0 followed by only 1s, or a leading 1 followed by only 0s. It has two strings at each length 1–5 and none at length zero, so its count is 10. 4. The overlap is exactly {0,1}. Longer strings in s contain both symbols, so cannot be in r. Inclusion-exclusion gives union size 11+10−2=19. 5. The complement count is 63−19=44. Answer: 44. A lengthwise check gives 0,0,0,4,12,28 excluded strings at lengths 0 through 5, again totaling 44.
L1 is described by b*ab*(ab*ab*)*. L2 contains all strings over {a,b} of length at most four. How many strings belong to both?
Answer & solution
Official answer: 15
Approach: Interpret the regex structurally before doing a length-by-length count.
1. Derivation. The regular expression has one initial a followed by any number of pairs of a’s, with arbitrary b runs between and around them. It therefore accepts exactly the strings with an odd positive number of a’s. For any positive length ℓ exactly half of the 2^ℓ binary strings have odd a-parity, by flipping one fixed position. Lengths1 through 4 contribute 1+2+4+8=15; ε has even parity and is excluded.
2. Explanation and checks. The one initial a plus any number of pairs makes the a-count odd; the b* runs admit arbitrary b’s before, between and after those a’s. For length 3 the allowable counts are one a or three a’s, giving C(3,1)+C(3,3)=4. For length 4 they give C(4,1)+C(4,3)=8. Lengths 1 and 2 contribute one and two. The empty string has no a and cannot match the mandatory initial a.
An NFA has nonfinal start s and final states u,v. Transitions: s—a→u, s—b→v, u—b→u and s, v—a→v and s; no other transitions. Choose its regular expression (plus means union): 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*).
Your answer
Answer & solution
Official answer: D
Each return to the nonaccepting start state consumes either ab*b through the upper accepting state or ba*a through the lower one. Any number of such excursions may occur. Finally the path must stop in an accepting state, consuming ab* or ba*. Thus the language is (ba*a+ab*b)*(ab*+ba*), D.
A useful state-elimination decomposition is a sequence of complete excursions back to s, then one final unfinished excursion into u or v. Since s is nonaccepting, the final factor must consume at least one symbol; option C incorrectly admits ε. Option B disallows mixing the two types of returning excursion before the last segment.
Over Σ={a,b}, L1={a^n w a^n : w∈Σ*}, L2={w x w^R : w,x∈Σ*, |w|,|x|>0}. Select true statements: A both regular; B both context-free; C L1 regular and L2 context-free; D both context-free but neither regular. The source does not explicitly state the allowed n in L1.
Select all that apply
Answer & solution
Official answer: A,B,C
In L1 the arbitrary middle word absorbs all content: if n=0 is allowed, L1=Σ*; if n is required positive, taking n=1 gives aΣ*a. Either reading is regular. L2 consists exactly of strings of length at least 3 whose first and last symbols agree: take w to be the first symbol and x the nonempty middle. Hence L2=aΣ+a ∪ bΣ+b is regular. Both are therefore context-free as well, so A, B, C are true and D is false.
For L2, any allowed decomposition has equal first and last symbols and at least one middle symbol. Conversely if those conditions hold, choose |w|=1 and put everything else in x. Longer equal/reversed boundary strings are optional witnesses, not extra restrictions. This existential choice is why the language is much simpler than a general palindrome language.
Which regexes describe binary multiples of three, allowing leading zeros and ε? 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)*. + denotes union.
Select all that apply
Answer & solution
Official answer: A; B; C
Use the remainder automaton r→(2r+b) mod3, start/accept 0. A describes concatenated excursions from 0: a 0 stays at 0, while 1 enters remainder 1, any number of blocks 01*0 returns to 1 via remainder 2, and final 1 returns to 0. B describes the same excursions by separating 11 from 10(1+00)*01: at remainder 2, either 1 or 00 loops back to 2, then 01 exits to 0. C is equivalent to A because arbitrary concatenations of zeros and nonzero excursions can be grouped into runs of zeros followed by runs of excursions. D is wrong: it cannot generate 1001 (binary9); every nonempty D word beginning 1 begins 11. Thus A, B, C. Leading zeros and the empty string are allowed as stated.
The remainder transition table is 0:0→0,1→1; 1:0→2,1→0; 2:0→1,1→2. A complete path from 0 back to 0 can be decomposed at every visit to state 0. This yields the excursion regex used in A. The counterexample 1001 has numeric value 9, so rejecting it conclusively refutes D without needing exhaustive enumeration.
Which regular expression denotes binary strings with an odd number of 1s? Here + means union. A ((0+1)*1(0+1)*1)*10*; B (0*10*10*)*0*1; C 10*(0*10*10*)*; D (0*10*10*)*10*. The official answer is MTA, not a letter.
Your answer
Answer & solution
Official answer: MTA
Our answer: No correct option; official MTA
Worked explanation
Checking a claimed regular expression needs both inclusions: every generated string must have odd parity, and every odd-parity string must be generated. A violates soundness because the arbitrary (0+1)* portions can introduce extra 1s: use the repeated block 111 and final 1 to generate 1111. B violates completeness on 10, because it ends in a mandatory 1. C violates completeness on 01, because its first symbol is 1. In D, zero repeated blocks give a leading 1; a positive number supplies at least two 1s before the final mandatory one, so 01 is again missing. In the corrected teaching expression 0*(10*10*)*10*, the repeated block contributes pairs of 1s and the final block contributes one; the surrounding zero runs allow arbitrary gaps and ends. This correction is explanatory only and does not replace official MTA scoring.
Derivation and answer
Each offered expression fails. A accepts 1111: choose 111 for one repeated block and the final 1, producing an even number of ones. B always ends in 1 and misses the valid string 10. C begins in 1 and misses 01. D also misses 01: zero repetitions begin with 1, while any positive repetition contributes at least two ones before the final 1. A correct expression is 0*(10*10*)*10*. The official key awards MTA, which is preserved rather than mapped to a letter.
A valid pumping length for a union of residue classes
Regular Expressions & Languages
Tap to enlarge
Over {a,b}, L = {a^(2+3k) : k≥0} ∪ {b^(10+12k) : k≥0}. Which offered value can be a pumping length? Choices: A 3; B 5; C 9; D 24. The question asks for a valid length, not necessarily the smallest one.
Your answer
Answer & solution
Official answer: D
Method: use the actual pumping-lemma conditions. For every word s with |s|≥p, find s=xyz with |xy|≤p, |y|≥1, and xyiz∈L for every integer i≥0.
1. Reject p=3, 5, or 9 using s=b10, which has length at least each candidate. Any nonempty y in such a decomposition consists only of b's and has length r with 1≤r≤p≤9. 2. Pumping up once more, i=2, produces length 10+r. For this all-b word to remain in L, r would have to be a multiple of 12. No r from 1 through 9 qualifies. Thus each of those three candidates fails. 3. Now take p=24. If s=am∈L and m≥24, set x=ε and y=a³. Pumping changes m by a multiple of 3, preserving m≡2 mod 3. Even at i=0, m−3≥21, and the permitted residue makes the remaining exponent an admitted nonnegative case. 4. If s=bm∈L and m≥24, set x=ε and y=b12. The first eligible such m is 34. Pumping changes m by multiples of 12; removing one block leaves at least 22, still an admitted length 10+12k. 5. Both constructions have nonempty y and |xy| equal to 3 or 12, at most 24. They therefore satisfy all requirements for every sufficiently long word in either branch.
Result: D, 24. A pumping length is an upper threshold at which suitable repetition is guaranteed; it does not have to equal a shortest accepted word or the least possible threshold.
Let Σ={0,1}; + denotes union and * Kleene star. Which regex specifies strings containing both 00 and 11 as substrings? A: Σ*0011Σ*+Σ*1100Σ*. B: Σ*(00Σ*11+11Σ*00)Σ*. C: Σ*00Σ*+Σ*11Σ*. D:00Σ*11+11Σ*00.
Your answer
Answer & solution
Official answer: B
A word must contain both a 00 occurrence and a 11 occurrence, in either order, with an arbitrary middle substring and arbitrary prefix/suffix. They cannot overlap because their symbols differ. Hence Σ*(00Σ*11+11Σ*00)Σ*, B. A forces adjacent blocks, C requires only one, and D disallows arbitrary outside context.
Take the earlier of a 00 occurrence and a 11 occurrence. Their positions cannot overlap, so one appears before the other with some possibly empty substring between them. This establishes the two alternatives in B. As a diagnostic example,001011 has both required pairs separated by 10, so it is valid but A rejects it. C incorrectly accepts 00 alone; D rejects valid words with extra prefix or suffix. Arbitrary prefix, middle and suffix are all needed.
Which languages are regular? L1={wxw^R:w, x∈{a, b}*, |w|, |x|>0}; L2={a^n b^m:m≠n, m, n≥0}; L3={a^p b^q c^r:p, q, r≥0}. A L1, L3; B L2 only; C L2, L3; D L3 only.
Your answer
Answer & solution
Official answer: A
L1 consists exactly of length≥3 strings with equal first/last symbols: choose the one-symbol w and nonempty interior x. Its regex is a(a+b)(a+b)*a + b(a+b)(a+b)*b, so regular. If L2 were regular, subtracting it from a*b* would make{an bn} regular, contradiction. L3=a*b*c* is regular. Thus L1, L3, A.
In L1, the first and last symbols must agree because w and its reversal surround x. Conversely, any length≥3 string with equal ends can choose a one-symbol w and the nonempty middle as x, so that simple description is exact and regular. L2 is the unequal-count complement within a*b*. If it were regular, subtracting it from regular a*b* would make the equal-count language regular, contradicting its pumping argument. L3 has the direct regular expression a*b*c*. Thus A contains exactly the regular choices.
Solve language equations X0=1X1, X1=0X1+1X2, X2=0X1+{ε}, where concatenation and union have their regular-expression meanings. Determine X0; option C is 1(0+10)*1. Options: A 10(0*+(10)*)1; B 10(0*+(10)*)*1; C 1(0+10)*1; D 10(0+10)*1+110(0+10)*1.
Your answer
Answer & solution
Official answer: C
Substitute X2=0X1+{epsilon} into X1=0X1+1X2 to obtain X1=(0+10)X1+1. Since the repeated-prefix language excludes epsilon, Arden’s lemma gives X1=(0+10)*1. Then X0=1X1=1(0+10)*1, C. The source’s X2 right side is 0X1, not 0X2.
Substitute X2 into X1: X1=0X1+1(0X1+ε)=(0+10)X1+1. Arden’s lemma says X=AX+B has unique solution A*B when ε is not in A. Here A={0, 10} excludes ε, giving X1=(0+10)*1. Prefixing the initial equation by 1 yields X0=1(0+10)*1. This expression includes 11 via zero repetitions and may add either 0 or 10 in the middle; using the wrong variable in the X2 equation would yield a different language.
Which language is regular? A: {aⁿbⁿ:n≥0}. B: {aⁿ:n is prime}. C: {w over {a,b}: w contains 3k+1 occurrences of b for some k∈ℕ}. D: {ww:w∈{0,1}*}.
Your answer
Answer & solution
Official answer: C
1. Method and setup. Finite-state memory can retain a count modulo a fixed constant, but cannot in general remember arbitrary equal block lengths, primality of unbounded lengths, or an arbitrary string for exact copying. For C, use states representing residues 0,1,2 of the b-count; a leaves the state unchanged and b advances it cyclically.
2. Work through the result and its assumptions. A DFA can count b symbols modulo 3 while ignoring a, accepting the residue 1 class; if natural k excludes 0, a finite initial-count adjustment still makes it regular. The equal-count language is nonregular by pumping; unary prime lengths are not ultimately periodic. The copy language is nonregular: intersection with 0*1*0*1* yields 0i1j0i1j, whose equal nonadjacent blocks defeat pumping on 0p1p0p1p. Thus only C.
Let L1={a^n:n≥0} and L2={b^n:n≥0}. Statements: I L1·L2 is regular; II L1·L2={a^n b^n:n≥0}. Which are correct? A only I; B only II; C both; D neither.
Your answer
Answer & solution
Official answer: A
1. Set up the reasoning. The variable n in each set definition is locally bound. Concatenation independently chooses any word from L1 and any word from L2, so it does not require their lengths to agree.
2. Derive the result. The concatenation is a*b*: choose the number of a symbols and the number of b symbols independently. This is regular, but it includes ab² and so is not the equal-count language. Only I holds, A.
3. Check the interpretation. The regular expression a*b* describes the concatenation. The witness abb belongs to it but not to the equal-count language in II, immediately separating the two claims.
L1 consists of binary strings with at least as many occurrences of substring 110 as 011. L2 consists of binary strings with at least as many occurrences of 000 as 111. Which is true? A L1 regular, L2 not; B L2 regular, L1 not; C both regular; D neither regular.
Your answer
Answer & solution
Official answer: A
1. Set up the reasoning. Count overlapping occurrences. For L1, examine maximal runs of at least two 1s: an entering 0 produces one 011 and a leaving 0 produces one 110. Every internal run contributes one of each.
2. Derive the result. For each maximal run of at least two 1s, an entering 0 contributes one 011 and a leaving 0 contributes one 110. Internal runs cancel; hence #110−#011 equals the indicator that the string starts 11 minus the indicator that it ends 11. A finite automaton can track these boundary facts, so L1 is regular. Intersect L2 with 0³0*1³1*: the resulting language is{0m1n: m≥n≥3}, because occurrences number m−2 and n−2. This is not regular: pumping down a zero in 0p1p violates m≥n. Thus L2 is not regular, A.
3. Check the interpretation. Only boundary runs can leave an imbalance, requiring finite memory. For L2, intersect with the regular pattern 0m1n, m,n≥3; counts become m-2 and n-2, demanding the unbounded comparison m≥n. Pumping zeros down from 0p1p contradicts regularity.
Over alphabet {a,b}, consider the regular expression a*b*(ba)*a*. What is the length of a shortest string outside its language?
Answer & solution
Official answer: 3
Step 1: A shortest counterexample requires checking every shorter length. The empty string is obtained by choosing zero repetitions everywhere; a and b are generated by their star factors. Step 2: All length-two strings occur: aa from a*, ab from a*b*, bb from b*, and ba from (ba)*. Step 3: The length-three word bab is absent. Without any ba pair, a*b*a* cannot switch back to b after a trailing a. If a ba pair is used, the remaining final b cannot be produced by the final a*, and extra pairs are too long. Step 4: Hence no shorter string is missing, while bab is missing, so the answer is 3.
Let L1=∅ and L2={a}. Evaluate L1 L2* ∪ L1*. A{ε}; B∅; C a*; D{ε, a}.
Your answer
Answer & solution
Official answer: A
The concatenation of the empty language with any language is empty. Meanwhile ∅*={ε}. Therefore the displayed union is{ε}, A.
Language concatenation requires one word from each operand. Since L1 contains no word at all, L1 L2* contains none, irrespective of L2*. A Kleene star always includes the concatenation of zero words, namely ε. With an empty base language there are no positive-length concatenations, so L1* contains exactly ε. Taking the union of ∅ with{ε} yields{ε}; do not confuse ∅ with the singleton language containing the empty word.
Given the language L = {ab, aa, baa}, which of the following strings are in L*?
1) abaabaaabaa 2) aaaabaaaa 3) baaaaabaaaab 4) baaaaabaa (A) 1, 2 and 3 (B) 2, 3 and 4 (C) 1, 2 and 4 (D) 1, 3 and 4
Q. 26 to Q. 55 carry two marks each.
Your answer
Answer & solution
Official answer: C
The blocks ab, aa and baa have distinct forced beginnings: at a, the next character decides ab versus aa; at b, only baa is possible. String 1 factors as ab·aa·baa·ab·aa; string 2 as aa·aa·baa·aa; and string 4 as baa·aa·ab·aa. For string 3, baaaaabaaaab, the forced parse is baa·aa·ab·aa·aa followed by a lone b, which is not a block. Its reachable complete-block prefix lengths are 0, 3, 5, 7, 9, 11, but its full length is 12. Thus exactly strings 1, 2, 4 belong to L*, C.
Check: Because no listed block is a prefix of another listed block, greedy block recognition cannot discard an alternative valid segmentation. This prefix-code property makes the forced parse failure of string 3 decisive rather than just one unsuccessful guess.
Let L be all binary strings with an even number of 1s, including zero 1s. Which regular expression represents L? Concatenation is implicit and * denotes Kleene star. Options: (A) (0*10*1)*; (B) 0*(10*10*)*; (C) 0*(10*1)*0*; (D) 0*1(10*1)*10*.
Your answer
Answer & solution
Answer: B (no official key was published)
A binary string with an even number of 1s can be decomposed into initial zeros followed by zero or more pairs of 1s, with any number of zeros after each 1. This is exactly 0*(10*10*)*, option B. Each repeated block contributes two 1s, while any string with 2k ones can be split into k such blocks. The outer star includes the zero-ones case, including epsilon.
Why the alternatives fail: A cannot generate a nonempty all-zero string; C cannot generate 11011, whose zero separates two adjacent pairs of ones; D always has at least its two explicit outer ones and therefore misses epsilon and all-zero strings. B allows arbitrary zeros before, between and after every pair, and its repetition count can be zero.
Describe (0+1)*0(0+1)*0(0+1)*: A strings containing 00; B at most two zeros; C at least two zeros; D strings beginning and ending with either 0 or 1.
Your answer
Answer & solution
Answer: C (no official key was published)
Each starred(0+1) factor permits any binary string, but the two explicit 0 symbols must occur in order. Hence the expression accepts exactly strings with at least two zeros, not necessarily adjacent, C.
Each explicit 0 in the expression must consume a separate symbol, so every generated string contains at least two zeros. The three starred factors can contain arbitrary binary strings, including more zeros, and may be empty. Conversely, choose any two zeros in a string and assign the prefix, intervening segment and suffix to the three starred factors. The zeros need not be adjacent, so 010 is accepted despite lacking substring 00. Hence C.
Match four NFAs to regular expressions. Each NFA has lower state L (initial and accepting), upper-left A and upper-right B. Unlisted transitions are absent. P: L−0→A, A−0→L and B, B−1→A and B; B is also accepting. Q: L−0→A, A−0→L, A−1→B, B−1→A, B−0→B; only L accepts. R: L−0→A, A−1→L and B, B−1→A, B−0→B; only L accepts. S has R’s transitions with both L and B accepting. Expressions: 1: ε+0(01*1+00)*01*; 2: ε+0(10*1+00)*0; 3: ε+0(10*1+10)*1; 4: ε+0(10*1+10)*10*.
1. Name the lower start state L, upper-left state A and upper-right state B. Every automaton accepts ε at L; every nonempty accepted path begins with 0 from L to A. In P, cycles from A back to A are 00 via L or 01*1 via B, and a finishing path to either accepting state is represented by 01*. 2. Hence P matches expression 1: ε+0(01*1+00)*01*. In Q, the A-cycles are 00 or 10*1, with final 0 to L, giving expression 2. In R, the A-cycles are 10 or 10*1, with final 1 to L, giving expression 3. 3. In S, the same cycles apply but B is also accepting, so a final 10* covers both possible accepting destinations, giving expression 4. Thus P–1,Q–2,R–3,S–4, option C.
(A) I and IV only (B) I and III only (C) I only (D) IV only
Your answer
Answer & solution
Answer: A (no official key was published)
1. I and IV are regular, giving A. I has expression a*(bb)*: n and m are independent and only the parity of the b-count is restricted. 2. IV has expression (a|b)*c(a|b)* because x and y need not be equal. II is {a2mbm}; applying the pumping lemma to a2pbp pumps only a symbols and destroys the required 2:1 relation. 3. III is not regular: if it were, subtracting it from the regular language a*b* would make {an bn} regular by closure under difference, a contradiction.
Which statement about regular languages is true? Options: (A) Every subset of a regular set is regular (B) Every finite subset of a nonregular set is regular (C) The union of two nonregular sets is nonregular (D) An infinite union of finite sets is regular
Your answer
Answer & solution
Answer: B (no official key was published)
1. Approach. A finite language is described by a finite union of its individual words. Closure under finite union does not imply closure under an arbitrary infinite union.
2. Derivation and interpretation. Every finite language is regular, regardless of the parent set, so B. A fails because nonregular languages are subsets ofΣ*. C fails by taking a nonregular language and its nonregular complement, whose union is Σ*. D fails because any nonregular language is an infinite union of singleton finite languages.
Which language is regular? In all options w and x are nonempty binary strings, w^R is the reversal of w, and Σ={0,1}. Options: (A) {ww^R:w∈Σ+} (B) {ww^R x:w,x∈Σ+} (C) {wxw^R:w,x∈Σ+} (D) {xww^R:w,x∈Σ+}
Your answer
Answer & solution
Answer: C (no official key was published)
1. Approach. The existential decomposition matters: for option C, w can always be chosen to have length one. This removes the apparent need to remember an arbitrarily long prefix. A direct regular expression is 0(0|1)+0 | 1(0|1)+1.
2. Derivation and interpretation. In C, every string wxwR has the same first and last symbol and length at least 3. Conversely any binary string of length≥3 with equal endpoints has such a representation by choosing w to be its first single symbol and x its nonempty middle. Thus C equals 0(0+1)+0 ∪1(0+1)+1 and is regular. A is the nonempty even-palindrome language and nonregular. For B, intersect with the regular language 0(11)*1 00 (11)*1 01. The result is{0 1k 00 1k 01:k positive odd}: the only possible even-palindrome prefix must match the two odd-length 1 blocks. This equality language is nonregular by pumping the first block. Hence B is nonregular. D is the reversal of B and is likewise nonregular.
A DFA over {a,b} has start state q0, accepting states q1,q2 and nonaccepting states q0,q3. Its complete transition table is: q0: a→q1,b→q0; q1: a→q2,b→q1; q2: a→q1,b→q2; q3: a→q1,b→q2. Which regular expression denotes its language? Here + denotes union. Options: (A) b*ab*ab*ab* (B) (a+b)* (C) b*a(a+b)* (D) b*ab*ab*
Your answer
Answer & solution
Answer: C (no official key was published)
1. Approach. Before the first a the machine stays in nonaccepting q0. Once an a occurs, every later transition stays within the accepting pair q1,q2. q3 cannot affect strings read from the start state.
2. Derivation and interpretation. The start state q0 loops on b and is not accepting. Its first a enters accepting q1. Thereafter a alternates between q1 and q2 and b loops in either accepting state, so every suffix over {a,b} is accepted. q3 is unreachable from q0. Thus exactly the strings containing at least one a are accepted: b*a(a+b)*, option C.
For binary string s, let n₀(s),n₁(s) count zeros and ones. Which language is not regular? Options: (A) {s:n₀(s) is a three-digit prime} (B) {s:for every prefix t of s, |n₀(t)−n₁(t)|≤2} (C) {s:|n₀(s)−n₁(s)|≤4} (D) {s:n₀(s) mod 7=0 and n₁(s) mod 5=0}
Your answer
Answer & solution
Answer: C (no official key was published)
1. A is regular because the permitted zero counts are finitely many three-digit primes; count zeros up to the maximum with an overflow state. B tracks prefix imbalance in{−2,−1,0,1,2}, rejecting immediately outside that range.
2. D tracks zero count modulo 7 and one count modulo 5. C only bounds the final imbalance and allows arbitrarily large intermediate imbalance.
3. Intersect C with 0*1* and pump 0p1p: pumping a nonempty block of initial zeros sufficiently many times makes the final difference exceed 4. Hence C is not regular.
4. Teaching check: A bound on every prefix permits a finite-state machine to reject immediately when its imbalance leaves a fixed range. A bound only on the final string allows arbitrarily large positive imbalance followed by enough ones to cancel it. Tracking this unbounded debt cannot be done with finitely many states.
For a binary string s let d(s) be its numerical value, for example d(101)=5. Classify L={s:d(s) mod 5=2 and d(s) mod 7≠4}. Options: (A) Recursively enumerable but not recursive (B) Recursive but not context-free (C) Context-free but not regular (D) Regular
Your answer
Answer & solution
Answer: D (no official key was published)
1. A finite automaton stores the current binary value modulo 35. Reading bit b replaces residue r by(2r+b) mod35.
2. Accept precisely residues r with r mod5=2 and r mod7≠4. This recognizes the language, so it is regular, D; leading zeros do not affect the construction.
3. Teaching check: The joint modulus 35 suffices because both congruence tests depend only on the value modulo 35. Starting at residue zero, scan bits left to right and update r←(2r+b) mod 35. A 35-state DFA with appropriate accepting residues is a constructive regularity proof.
Grammar G has S→bS | aA | b; A→bA | aB; B→bB | aS | a. Na(w),Nb(w) count a,b symbols. Which describes L(G) within {a,b}^+ (nonempty words)? Options: (A) {w:Na(w)>3Nb(w)} (B) {w:Nb(w)>3Na(w)} (C) {w:Na(w)=3k, k∈{0,1,2,…}} (D) {w:Nb(w)=3k, k∈{0,1,2,…}}
Your answer
Answer & solution
Answer: C (no official key was published)
1. Interpret S,A,B as states tracking the number of a symbols modulo 3: a advances S→A→B→S, while b leaves the state unchanged. Terminating production S→b ends with residue 0, and B→a also ends with residue 0.
2. Consequently every generated word has #a divisible by 3. Conversely any nonempty word with that property can be scanned along these transitions; if its last symbol is b it terminates via S→b, and if its last symbol is a it terminates via B→a.
3. Thus L={w in {a,b}^+ : #a(w)≡0 mod3}, option C in the stated positive-word universe.
4. Teaching check: There is no ε production, so the empty word is excluded despite having zero a symbols. The problem explicitly uses {a,b}^+, which resolves that apparent exception. Each a advances one of three residue states while any b preserves it.
Which regular expression denotes the same language as 0*(10*)*? Here + means union. A. (1*0)*1*; B. 0+(0+10)*; C. (0+1)*10(0+1)*; D. None of these.
Your answer
Answer & solution
Answer: A (no official key was published)
1. For instance, 0010010 splits as 00·100·10 under the given expression. In A it splits into zero-terminated blocks with a final run of ones. B cannot produce the single string 1, and C requires a substring 10 and thus misses ε,0,1. This distinguishes the alternatives without merely appealing to a pattern resemblance.
2. Every binary string can be divided into an initial zero run followed by successive 1-and-zero-run blocks, so 0*(10*)*=Σ*. Likewise(1*0)*1* parses successive zero-terminated blocks followed by a final one run and also gives Σ*. Thus A. The other listed expressions do not cover exactly all binary strings.
Assess regularity of L1={0^(2n):n≥1} and L2={0^m1^n0^(m+n):m,n≥1}. Choices A/B/C/D assert only L1, only L2, both, or neither is regular.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: S1 contains positive even-length strings of zeros, described by regular expression 00(00)*, so it is regular.
Step 2: Suppose S2 were regular with pumping length p. Choose 0p1p02p. Any pumping segment in the first p symbols consists of k≥1 initial zeros. Pumping it out changes the first zero-block length to p−k while leaving the final zero block length 2p. That final block no longer equals the sum(p−k)+p. This contradicts the pumping lemma.
Therefore S2 is not regular and only S1 is correct, A.
Which languages are regular? L1={ww:w∈{a,b}*}; L2={ww^R:w∈{a,b}*}; L3={0^(2i)}; L4={0^(i²)}, interpreting valid nonnegative lengths. Choices: L1/L2; L2/L3/L4; L3/L4; only L3.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: L3 contains even-length unary strings, recognized by a two-state parity machine. Interpreting only nonnegative string lengths, negative integer parameters do not add new words.
Step 2: L1={ww} is nonregular: prefixes an b are pairwise distinguishable, since suffix an b makes a square with that prefix but not with am b for m≠n. L2={wwR} is nonregular: prefixes an b are distinguished by suffix b an; the resulting word am bb an is an even palindrome exactly when m=n.
Step 3: L4 has square unary lengths. For pumping length p, pump a nonempty segment of length k≤p in 0p². Pumping once more gives length p²+k strictly between consecutive squares p² and(p+1)², contradiction.
Let S=(a+b*)* and T=(a+b)* over {a,b}. Are S and T in a proper-subset relation, equal, or disjoint?
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Every block allowed inside S is either a or a finite run of b symbols. Concatenating such blocks can produce every word over {a,b}, since individual a and b symbols are both available.
Step 2: No other symbol can appear, so S⊆{a,b}*. The expression T also generates exactly {a,b}*, including ε.
Hence S=T, option C. The inner star on b does not restrict the outer star’s ability to concatenate individual symbols.
Compare A=(01+1)* and B=((01)*1*)*: proper inclusion, equality, or incomparable?
Your answer
Answer & solution
Answer: D: equality (no official key was published)
Every block in B is a sequence of 01 blocks followed by a sequence of 1 symbols, all of which are permitted individual blocks of A. Thus B⊆A. Conversely B can produce an individual 01 by selecting one occurrence in (01)* and none in 1*, and can produce an individual 1 by the reverse choice. Its outer star concatenates any sequence of these, so A⊆B. Both include the empty string. Therefore A=B, D.
Which is regular: powers of two written in binary, powers of two in unary, equal numbers of zeros and ones, or{1, 101, 11011, 1110111, …}?
Your answer
Answer & solution
Answer: A (no official key was published)
Binary powers of two are exactly 10*, a regular expression, so a DFA recognizes A. Unary powers of two have gaps that keep increasing and are not ultimately periodic, as every unary regular language must be. Equal zero/one counts would yield nonregular 0n1n after intersection with 0*1*. The displayed final pattern requires matching runs of ones on either side of a zero and is likewise nonregular by pumping or distinguishable prefixes. Hence A under the evident continuation of that example list; an ellipsis itself is not a formal language definition.
Which does not contain 1101: A 110*(0+1), B1(0+1)*101, C(10)*(01)*(00+11)*, D(00+(11)*0)*?
Your answer
Answer & solution
Answer: C, D (no official key was published)
A accepts 1101 using one zero in 0* and final 1. B accepts it with an empty middle star:1·101. For C, the initial 10 block cannot be used because the word starts 11; neither can the next 01 block. The remaining (00+11)* cannot partition 1101 into equal-symbol pairs because its last pair is 01. Thus C rejects. Every nonempty block of D ends in 0, so every nonempty word of D ends in 0;1101 ends in 1 and is rejected too. The paper shows these expressions. A single-answer instruction therefore conflicts with the two rejecting choices.
Which is false: finite subsets of nonregular languages are regular; every subset of a regular language is regular; finite subsets of regular languages are regular; intersection preserves regularity?
Your answer
Answer & solution
Answer: B (no official key was published)
Every finite language is regular: form a finite union of its individual words. Thus A and C hold regardless of the larger language. Regular languages are closed under intersection using a product DFA, so D holds. But the regular language{0, 1}* contains the nonregular subset{0n1n:n≥0}. Hence arbitrary subsets need not be regular, disproving B. Finite-subset closure must not be extrapolated to unrestricted infinite subsets.
Give a regular expression for binary strings in which every 0 is immediately followed by exactly k consecutive 1s and preceded by at least k consecutive 1s, for fixed nonnegative integer k.
Answer & solution
Answer: 1* ∪ 1^k 1* 0 1^k (0 1^k)*. (no official key was published)
Interpret “exactly k” as the length of the entire run of consecutive 1s immediately after a 0. Write 1k for k copies of the symbol 1, not a variable exponent inside the regex. One expression is
1* ∪ 1k 1* 0 1k (0 1k)*.
The first branch handles strings with no zeros, including ε. Their condition is vacuously true; they must not be discarded merely because they contain fewer than k ones. In the second branch, the initial run 1k1* has at least k ones, so the first zero has the required predecessor run. Every zero then contributes the block 01k. Repeating that block gives exactly k ones between consecutive zeros, simultaneously satisfying the preceding and following requirements. The last zero is also followed by exactly k ones, with no extra trailing ones.
Conversely, any valid string containing a zero has an initial run of at least k ones. After its first zero, each run of ones has length exactly k, until the string ends or the next zero begins. It therefore has the displayed form. For k=2, 11011 and 111011011 are accepted, whereas 1011 lacks enough leading ones and 110111 has too many final ones. For k=0 the formula reduces to 1*0*: no one may occur after the first zero. If “followed by k ones” meant at least k rather than exactly k, a different language would result.
An identifier has one through six letters/digits, with a letter first. Give a regular expression.
Answer & solution
Answer: L(ε|A|A²|A³|A⁴|A⁵), A=L∪D. (no official key was published)
Let L denote the finite union of permitted letters and D the union of decimal digits. Let A=L|D. The first character must be from L. It can be followed by zero through five alphanumeric characters, giving
L(ε | A | AA | AAA | AAAA | AAAAA).
With repetition shorthand this is L A{0,5}. The expanded expression above uses only ordinary regular-expression union, concatenation and ε; braces are not essential notation.
A one-letter identifier follows the ε branch; a six-character one follows AAAAA. No branch accepts an empty identifier or a first digit, and none permits a seventh character. Conversely any permitted identifier can be decomposed into its initial letter and its remaining zero to five alphanumeric symbols, so it is accepted. The actual letter alphabet, such as upper/lowercase distinctions, is a language-design input; underscores are not included because the question permits only letters and digits.
Which regex describes binary strings with no substring 100? Choice D is 0*(10+1)*.
Your answer
Answer & solution
Answer: D (no official key was published)
Any leading run of zeros is harmless and is covered by 0*. After the first 1, there cannot be two consecutive zeros, or the preceding 1 followed by those zeros would form 100. Thus the remaining word can be partitioned into blocks 1 and 10, covered by (1+10)*. Conversely, a word built this way has no pair of zeros after a 1, so it cannot contain 100. Hence 0*(10+1)* is exactly the desired language, D. It includes ε and all-zero strings, which also avoid the forbidden substring.
Compare (i)(00)*(ε+0), (ii)(00)*, (iii)0*, and (iv)0(00)*. Which expressions are equivalent?
Your answer
Answer & solution
Answer: C: (i) and (iii) (no official key was published)
Expression (00)* produces every even number of zeros, including zero. Appending either ε or one zero therefore produces every nonnegative length, exactly 0*. Expression (ii) alone excludes odd lengths; expression (iv) produces only odd lengths and excludes ε. Thus only (i) and (iii) describe the same language. Checking both ε and a one-symbol word already distinguishes the parity-restricted alternatives from the full unary language.
Which language over {a,b} is regular: (A) all words with equally many a and b symbols; (B) {a^n b^n:n≥1}; (C) all words with more a symbols than b symbols; (D) {a^m b^n:m≥1,n≥1}?
Your answer
Answer & solution
Answer: D (no official key was published)
The displayed language has no equality or inequality coupling the two block lengths. It is described by the regular expression aa*bb*: read at least one a, then at least one b. A finite automaton only needs to remember which block it is reading and reject a later a. In contrast, requiring equal block lengths or comparing their unbounded counts generally needs more than finite memory. Thus the unrestricted positive two-block choice D is regular; the independent quantifiers m,n are crucial.
An identifier is one letter followed by zero or more letters or digits. With letter set L and digit set D, choose its expression.
Your answer
Answer & solution
Answer: B: L(L∪D)* (no official key was published)
The initial L enforces exactly one initial letter. Every subsequent character may independently be a letter or digit, represented by L∪D, and the star allows zero or more such characters. Thus a one-letter identifier is allowed, but an empty identifier or one beginning with a digit is not. Expressions that star an alternating letter-digit pair impose an unjustified pattern, while starring or plussing L∪D alone permits a digit first. The concatenation L(L∪D)* captures precisely the requirement.
A grammar versus regular expressions for equal counts
Regular Expressions & Languages
Tap to enlarge
For L={x^n y^n:n≥1}, compare I E→xEy|xy; II xy | x⁺xyy⁺; III x⁺y⁺. Which define L?
Your answer
Answer & solution
Answer: A: I only (no official key was published)
Grammar I starts with xy and each recursive wrapping adds one x to the front and one y to the end. It therefore generates exactly equal positive block counts. Expression III permits unequal counts, for example xyy. Expression II permits independently sized positive runs before its extra x and after its first y; for example xxyyy is accepted but has unequal counts. Hence neither regular expression enforces equality. Only I defines L, in agreement with the fact that the equal-count language is not regular.
Let Σ={0,1}, L=Σ*, R={0^n1^n:n>0}. Classify L∪R and R as regular or nonregular.
Your answer
Answer & solution
Answer: C: regular,nonregular (no official key was published)
Every member of R is a binary word, so R⊆Σ*=L. Hence L∪R=L, which is regular. R itself is nonregular: if its pumping length were p, the word 0p1p would have a pumpable nonempty segment entirely among its first p zeros. Pumping that segment changes the number of zeros but not ones, leaving R and contradicting the lemma. Thus adjoining R to a universal regular language does not make the union nonregular.
Start/accept state A loops on 0 and goes to accept B on 1. B loops on 1 and goes to nonaccepting trap C on 0; C loops on both. Give a regex.
Answer & solution
Answer: 0*1* (no official key was published)
While in A the machine reads any number of zeros, possibly none. The first one moves it to B, where further ones are allowed. A zero after that moves to the trap and cannot be recovered. Thus accepted words are exactly a block of zeros followed by a block of ones, with either block allowed empty: 0*1*. The empty word is accepted because the start state A is accepting. The accepting mark on B permits words ending after one or more ones.
Similar questions1 more → · asked again: GATE 1999, Q6(a)
A regular union does not determine its operand
Regular Expressions & Languages
Tap to enlarge
If L1 and L1∪L2 are regular, must L2 be regular? Prove the answer.
Answer & solution
Answer: No. Take L1={a,b}* and L2={a^n b^n:n≥0}. (no official key was published)
Choose the common alphabet Σ={a,b}, let L1=Σ*, and let L2={an bn:n≥0}. L1 is recognized by a single accepting state with a loop on each alphabet symbol. Since L2⊆L1, their union is Σ*, also regular. Nevertheless L2 is not regular.
To verify the last assertion, suppose a pumping length p exists. The word ap bp must have a decomposition xyz with |xy|≤p and |y|>0. Consequently y consists of k≥1 copies of a. Pumping y zero times gives ap−kbp, which is not in L2 because the numbers of a and b differ. This contradicts the pumping lemma.
The tempting subtraction argument is invalid: (L1∪L2) minus L1 equals L2 minus L1, not necessarily L2. Regularity of the union controls the portion of L2 outside L1, but places no constraint on its arbitrary portion inside L1. Our counterexample puts all of L2 inside L1, making that gap explicit.
The copies print A r(*)=r* and B (r*s*)=(r+s)*, plus C (r+s)*=r*+s* and D r*s*=r*+s*. Which identities are justified?
Select all that apply
Answer & solution
Answer: Literal A malformed, B/C/D false; intended A/B would need missing outer stars (no official key was published)
A standard true identity is (r*)*=r*, but the source’s r(*) is not that well-formed expression. Another true identity is (r*s*)*=(r+s)*, which requires an outer star absent from printed B. For literal B, take r=a, s=b: ba belongs to (a+b)* but not a*b*. For C, ab belongs to the left but neither a* nor b*. For D, ab belongs to a*b* but not a*+b*. Thus the often-intended answers A, B are conditional repairs, not identities established by the literal printed notation. The missing-star issue is retained as a source discrepancy.
True or false? L={0ⁿ : n is prime} is not regular. Prove your answer.
Answer & solution
Answer: True. Pump a prime-length q word with i=q+1 to obtain composite length q(1+|y|). (no official key was published)
True. Suppose for contradiction that L is regular, and let p≥1 be its pumping length. There is a prime q≥p, because primes are unbounded. Choose w=0q∈L. For any pumping-lemma decomposition w=xyz with |xy|≤p and |y|≥1, let d=|y|, so 1≤d≤p.
The pumping lemma requires xyi z∈L for every integer i≥0. Choose i=q+1. This word has length |xz|+(q+1)|y| = (q−d)+(q+1)d = q+qd = q(1+d). Both factors exceed one: q is prime and therefore q≥2, while d≥1 gives 1+d≥2. The length is composite. Consequently xyq+1z∉L, contradicting the pumping lemma.
The contradiction holds for every valid decomposition, because the same choice i=q+1 works for every positive d. We therefore refute the existence of a pumping length, and L is nonregular. Choosing an arbitrary fixed pump such as i=2 would not suffice: q+d might itself be prime for some decompositions. The deliberately selected exponent makes the resulting length a multiple of q larger than q.
Let r=1(1+0)*, s=11*0, t=1*0. Choose A L(s)⊆L(r) and L(s)⊆L(t); B reverse first inclusion; C L(s)=L(t); D L(t)⊆L(s); E none.
Select all that apply
Answer & solution
Answer: A (no official key was published)
Every s-word is one or more 1s followed by a single 0. It starts with 1 and has an arbitrary binary suffix, so it belongs to r. It also consists of zero or more 1s followed by 0, so it belongs to t. The inclusions are strict: 1 belongs to r but not s, and 0 belongs to t but not s. These witnesses refute the reverse inclusion and equality choices. Kleene star in 11*0 applies only to the second 1; the mandatory initial 1 is what excludes 0 from s.
For a finite language over a finite alphabet, choose strongest claim: possibly undecidable, TM-recognizable, context-sensitive, regular, none.
Select all that apply
Answer & solution
Answer: D: regular (no official key was published)
Write the finite language as{w1, …, wk}. Each fixed word has a regular expression obtained by concatenating its symbols, and their finite union is a regular expression for the whole language. The empty language and words containing ε also fit the regular class. Hence it is regular, which already implies decidability and TM recognizability. Those weaker true classifications are not the strongest requested answer. The proof is existential: it does not claim that an arbitrary description of an unknown finite language makes its entire list immediately computable.