Regular Expression · Theory of Computation
19 questions · asked in 14 of 27 years (2000–2026)
MCQ 16 · MSQ 1 · NAT 21-mark 15 · 2-mark 4
2000Questions per year2026
Questions 1–5 of 19
Consider the following two regular expressions over the alphabet :
The total number of strings of length less than or equal to 5 , which are neither in nor in , is ____
The total number of strings of length less than or equal to 5 , which are neither in nor in , is ____
Answer: 44
Count of all strings of length 0 to 5: .
- For : the empty string and the all-0 and all-1 strings of lengths 1-5 give .
- For : at each length 1-5 we get strings of the form and . Length 1 ("0", "1") is already in r, so the new strings are .
Strings in r or s: . Strings in neither: .
Answer: 44
- For : the empty string and the all-0 and all-1 strings of lengths 1-5 give .
- For : at each length 1-5 we get strings of the form and . Length 1 ("0", "1") is already in r, so the new strings are .
Strings in r or s: . Strings in neither: .
Answer: 44
Which one of the following regular expressions is equivalent to the language accepted by the DFA given below?
Answer: (A)
In the DFA, 0 keeps the state, and 1 switches between the start state and the final state. So it accepts the strings with an odd number of 1s.
Check : stays at the start state, the first 1 moves to the final state, and then each is the loop at the final state, while each goes back to the start state, loops on 0s, and returns to the final state. Every string with an odd number of 1s is split this way, so (A) matches the DFA.
Why the others fail:
- (B) gives the empty string (zero 1s, so the DFA rejects it) and never gives "1" (every block has three 1s).
- (C) cannot give "111", which has three 1s: after the first 1, every next block starts with 0.
- (D) must start with 0, so it cannot give "1".
Answer: (A)
Check : stays at the start state, the first 1 moves to the final state, and then each is the loop at the final state, while each goes back to the start state, loops on 0s, and returns to the final state. Every string with an odd number of 1s is split this way, so (A) matches the DFA.
Why the others fail:
- (B) gives the empty string (zero 1s, so the DFA rejects it) and never gives "1" (every block has three 1s).
- (C) cannot give "111", which has three 1s: after the first 1, every next block starts with 0.
- (D) must start with 0, so it cannot give "1".
Answer: (A)
Let M be the 5-state NFA with -transitions shown in the diagram below:
Which one of the following regular expressions represents the language accepted by M ?
Which one of the following regular expressions represents the language accepted by M ?
Answer: (B)
From state 1, an move goes to 2 (final) or to 4.
- Through 2: 0 swaps between 2 and 3. Ending at 2 gives . From 3 (after ), take to 5, then .
- Through 4: read 1 to reach 5, then .
Union: . As :
(The other options miss "0" or , or wrongly accept "11".)
Answer:
- Through 2: 0 swaps between 2 and 3. Ending at 2 gives . From 3 (after ), take to 5, then .
- Through 4: read 1 to reach 5, then .
Union: . As :
(The other options miss "0" or , or wrongly accept "11".)
Answer:
Consider the Deterministic Finite-state Automaton (DFA) 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 ?
Which one of the following regular expressions correctly describes the language accepted by ?
Answer: (C)
Start at s: input 0 sends the DFA to the dead state r, so every accepted string must begin with 1, which takes it to the final state p.
At p: input 0 stays at p. Input 1 goes to q, and from q only another 1 goes back to p (input 0 goes to r).
So after the first 1, the string is made of repeats of "0" or "11": .
Answer:
At p: input 0 stays at p. Input 1 goes to q, and from q only another 1 goes back to p (input 0 goes to r).
So after the first 1, the string is made of repeats of "0" or "11": .
Answer:
Consider the following definition of a lexical token for an identifier in a programming language, using extended regular expressions:
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)
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)
Answer: (C)
A valid identifier starts with one letter. After that it can have any mix of letters and digits.
- (A): The edge lets a string skip the first letter. So "1" or the empty string is accepted so this is wrong.
- (B): Once a branch is chosen, only letters or only digits can follow. So "a1b" is rejected so this is wrong.
- (C): One letter comes first. Then, from the final state, the loop takes any number of letter-or-digit steps so this is correct.
- (D): It forces "letter digit" pairs. So "ab" is rejected so this is wrong.
Answer: C
- (A): The edge lets a string skip the first letter. So "1" or the empty string is accepted so this is wrong.
- (B): Once a branch is chosen, only letters or only digits can follow. So "a1b" is rejected so this is wrong.
- (C): One letter comes first. Then, from the final state, the loop takes any number of letter-or-digit steps so this is correct.
- (D): It forces "letter digit" pairs. So "ab" is rejected so this is wrong.
Answer: C
Keep practising