Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

An individual token is called ________(a) Lexeme(b) Lex(c) Lexeme & Lex(d) None of the mentionedThe question was posed to me in exam.The origin of the question is Lexical Analyser topic in portion Finite Automata and Regular Expression of Compiler

Answer»

The correct OPTION is (a) LEXEME

The best EXPLANATION: INDIVIDUAL TOKEN is also Called Lexeme.

2.

Which phase of the compiler is Lexical Analyser?(a) First(b) Second(c) Third(d) None of the mentionedThe question was posed to me in class test.This is a very interesting question from Lexical Analyser topic in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct answer is (a) First

For EXPLANATION: LEXICAL Analyzer is First Phase of COMPILER.

3.

What is another name for Lexical Analyser?(a) Linear Phase(b) Linear Analysis(c) Scanning(d) All of the mentionedThis question was posed to me in class test.My doubt is from Lexical Analyser in section Finite Automata and Regular Expression of Compiler

Answer»

Correct OPTION is (d) All of the mentioned

To elaborate: Lexical Analyzer is also CALLED “Linear PHASE” or “Linear ANALYSIS” or “Scanning“.

4.

The context free grammar is ambiguous if ______________(a) The grammar contains non-terminals(b) Produces more than one parse tree(c) Production has two non-terminals side by side(d) None of the mentionedThe question was asked by my college professor while I was bunking the class.This question is from Lexical Analyser in division Finite Automata and Regular Expression of Compiler

Answer»

The correct choice is (b) Produces more than one PARSE TREE

The explanation: Since more than one parse tree is generated HENCE one than OPTION is AVAILABLE .Therefore it’s ambiguous.

5.

If L1 and L2 are regular languages is/are also regular language(s).(a) L1 + L2(b) L1L2(c) L1(d) All of the mentionedThis question was addressed to me in class test.My question is based upon Obtaining the regular Expression from the Finite automata topic in chapter Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT choice is (d) All of the mentioned

Explanation: All these expression GIVE US a regular GRAMMAR when L1 and L2 are regular.

6.

The set of all strings over ∑ = {a,b} in which strings consisting a’s and b’s and ending with in bb is?(a) ab(b) a*bbb(c) (a+b)* bb(d) All of the mentionedThis question was addressed to me during an online exam.This intriguing question comes from Obtaining the regular Expression from the Finite automata topic in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct CHOICE is (c) (a+b)* BB

For explanation: Only this EXPRESSION ends with bb only.

7.

Which of the following pairs of regular expression are equivalent?(a) 1(01)* and (10)*1(b) X(xx)* and (xx)*x(c) 1(01)* and (10)*1 & X(xx)* and (xx)*x(d) None of the mentionedThe question was asked in my homework.The query is from Obtaining the regular Expression from the Finite automata topic in section Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT answer is (c) 1(01)* and (10)*1 & X(xx)* and (xx)*x

The best I can explain: R1 and R2 are REVERSE of each other. If ant ONE of them can be generated them the other can be generated as well.

8.

Which one of the following is FALSE?(a) Every NFA can be converted to DFA(b) Every subset of a recursively enumerable set is recursive(c) All of the mentioned(d) None of the mentionedThis question was addressed to me by my college professor while I was bunking the class.The above asked question is from Minimization of DFA topic in division Finite Automata and Regular Expression of Compiler

Answer»

Right option is (b) EVERY SUBSET of a RECURSIVELY enumerable set is recursive

Easiest EXPLANATION: Every subset of a recursively enumerable set is recursive.

9.

How many minimum states are required to find whether a string has odd number of 0’s or not?(a) 1(b) 2(c) 3(d) 4This question was addressed to me by my school teacher while I was bunking the class.This is a very interesting question from Obtaining the regular Expression from the Finite automata in section Finite Automata and Regular Expression of Compiler

Answer» RIGHT ANSWER is (b) 2

Easy explanation: 2 minimum STATES are required to FIND WHETHER a string has odd number of 0’s or not.
10.

The set of all strings over ∑ ={a,b} in which a single a is followed by any number of b’s a single bfollowed by any number of a’s is?(a) ab* + ba*(b) ab*ba*(c) a*b + b*a(d) None of the mentionedThe question was posed to me by my school teacher while I was bunking the class.Origin of the question is Obtaining the regular Expression from the Finite automata topic in division Finite Automata and Regular Expression of Compiler

Answer» RIGHT option is (a) ab* + ba*

Easiest explanation: ab*+ba* is the expression in which a SINGLE a is FOLLOWED by any NUMBER of B’s a single b followed by any number of a’s.
11.

It has encoded within it information on the possible sequences of characters that can be contained within any of the tokens it handles. The mentioned function is performed by?(a) Scanner(b) Parser(c) Syntactic Analyser(d) All of the mentionedThe question was asked during an interview for a job.I'm obligated to ask this question of Lexical Analyser in division Finite Automata and Regular Expression of Compiler

Answer»

The correct choice is (a) Scanner

To elaborate: The FIRST STAGE, the scanner, is FSM. It has ENCODED information on the POSSIBLE SEQUENCES of characters that can be contained within any of the tokens it handles.

12.

For every DFA, there is an ε-NFA that accepts the same language.(a) True(b) FalseThe question was asked by my school principal while I was bunking the class.The doubt is from The NFA with epsilon-moves to the DFA-2 topic in section Finite Automata and Regular Expression of Compiler

Answer» CORRECT CHOICE is (a) True

To elaborate: For EVERY DFA, there is an ε-NFA that accepts the same language and Vice VERSA.
13.

The string (a)|((b)*(c)) is equivalent to ______________(a) Empty(b) abcabc(c) b*c|a(d) None of the mentionedThe question was asked during an online exam.Question is from Obtaining the regular Expression from the Finite automata in chapter Finite Automata and Regular Expression of Compiler

Answer»

The correct answer is (c) b*c|a

The EXPLANATION: Either b or a can lead FOLLOWED by c this expression can be ACHIEVED by C as WELL.

14.

Which of the lexical analyser can handle Unicode?(a) Java CC(b) JFLex(c) Quex(d) All of the mentionedI had been asked this question during a job interview.I'd like to ask this question from Lexical Analyser topic in section Finite Automata and Regular Expression of Compiler

Answer»

Correct option is (d) All of the mentioned

For explanation: JavaCC – JavaCC generates lexical ANALYZERS written in Java.

JFLex – A lexical ANALYZER GENERATOR for Java.

Quex – A fast universal lexical analyzer generator for C and C++.

FsLex – A lexer generator for byte and UNICODE character input for F#.

15.

The language accepted by this DFA is?(a) b*ab*ab*ab*(b) (a+b)*(c) b*a(a+b)*(d) b*ab*ab*I had been asked this question in unit test.My enquiry is from Minimization of DFA in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct answer is (C) B*a(a+b)*

BEST explanation: INITIALLY circle s around b so b* then a then FOLLOWED by (a+b)*.

16.

The parse tree below represents a rightmost derivation according to the grammar S → AB, A → aS|a, B → bA. Which of the following are right-sentential forms corresponding to this derivation?(a) aAbAba(b) aababa(c) aABba(d) aSbaThe question was posed to me in class test.This intriguing question originated from The NFA with n-moves to the DFA in division Finite Automata and Regular Expression of Compiler

Answer» CORRECT option is (B) aababa

Best explanation: S => AB => AbA => Aba => ASBA => aABba => aAbAba => aAbaba => aababa.
17.

If string s is accepted by this DFA, which of these strings cannot be suffix of s?(a) 111001(b) 111111(c) 111000(d) 101010The question was posed to me in a national level competition.My doubt stems from The NFA with n-moves to the DFA in portion Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT answer is (a) 111001

For explanation I would say: 111001 cannot be the suffix of any string accepted by this DFA. Suppose s=w111001. No matter what state the DFA reaches after READING w, it will go to state D after reading “111”, then go to state B after reading “00” and finally reaches state C after reading “1”.

18.

Find the pair of regular expressions that are equivalent.(a) (0+1)* and (0*+1*)*(b) (0+1)* and (0+1*)*(c) (0+10)* and (0*+10)*(d) All of the mentionedThis question was addressed to me at a job interview.My doubt is from The NFA with n-moves to the DFA topic in division Finite Automata and Regular Expression of Compiler

Answer» RIGHT OPTION is (d) All of the mentioned

Easy EXPLANATION: All generate all strings of 0’s and 1’s thus are these pairs are EQUIVALENT.
19.

For the following grammar: S → A | B | 2 A → C0 | D B → C1 | E C → D | E | 3 D → E0 | S E → D1 | S Identify all the unit pairs.(a) D,C(b) A,B(c) B,C(d) A,CThe question was posed to me during an internship interview.My question is based upon The NFA with n-moves to the DFA in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct choice is (a) D,C

The explanation is: The cycle of unit-productions S → A → D → S says that any PAIR INVOLVING only S, A, and D is a unit pair. Similarly, the cycle S → B → E → S tells US that any pair involving S, B, and E is a unit pair.

20.

Consider the machine M:The language recognized by M is :(a) {w ∈ {a, b}* / every a in w is followed by ex¬actly two b’s}(b) {w ∈ {a, b}* every a in w is followed by at least two b’}(c) {w ∈ {a, b}* w contains the substring ‘abb’}(d) {w ∈ {a, b}* w does not contain ‘aa’ as a substring}This question was addressed to me in class test.My doubt stems from Minimization of DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT option is (b) {w ∈ {a, b}* every a in w is followed by at least TWO b’}

Explanation: We can try some SAMPLE strings like aba, abbbabbb.

21.

Which one of the following is TRUE?(a) The language L={a^n b^n |n>0 } is regular(b) The language L={a^n|n is prime } is regular(c) The language L={w|w has 3k+1 b’s for some k } is regular(d) None of the mentionedThis question was addressed to me in an interview.My question is taken from Minimization of DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer» CORRECT choice is (c) The LANGUAGE L={w|w has 3k+1 b’s for some K } is regular

The explanation is: Onlyfor this option wecan build a FA.
22.

Which of the following strings is NOT in the Kleene star of the language {011, 10, 110}?(a) 01(b) 10(c) 110(d) 10011101The question was asked in my homework.This question is from The NFA with n-moves to the DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer» RIGHT option is (d) 10011101

The explanation: Every string in the language {011, 10, 110}* has to be formed from ZERO or more uses of the strings 011, 10, and 110. A string MAY be USED more than once.
23.

Examine the following DFA: If input is 011100101, which edge is NOT traversed?(a) A B(b) C(c) C D(d) D AThis question was addressed to me in an interview.My enquiry is from The NFA with n-moves to the DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct choice is (C) C D

The BEST I can EXPLAIN: The states traversed are ABDBDABDAC, and the only EDGE not traversed C D.

24.

If P, Q, R are three regular expressions and if P does not contain a then the equation R = R + RP has a unique solution given by?(a) R = QP*(b) R = P*Q(c) R = RP(d) None of the mentionedI had been asked this question in examination.Question is taken from Obtaining the regular Expression from the Finite automata in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct choice is (a) R = QP*

Explanation: It is an IMPORTANT law primarily USED in CONVERSION.

25.

Two Important lexical categories are __________(a) White Space(b) Comments(c) None of the mentioned(d) White Space & CommentsThe question was posed to me in homework.My question is taken from Lexical Analyser in division Finite Automata and Regular Expression of Compiler

Answer»

Right OPTION is (d) WHITE Space & Comments

Best EXPLANATION: Two IMPORTANT common lexical categories are white space and comments.

26.

Choose the correct statement for the following daigram.(a) For the language accepted by A which is also a minimal DFA(b) A accepts all strings over {0,1} of length at least 2(c) All of the mentioned(d) None of the mentionedI got this question during an internship interview.This intriguing question originated from Minimization of DFA in division Finite Automata and Regular Expression of Compiler

Answer» RIGHT option is (c) All of the mentioned

To explain I would say: The DFA can be minimized to two STATES and the SECOND STATE is final state .We reach second state after a 0.
27.

If the NFA N has n states, then the corresponding DFA D has 2n states.(a) True(b) FalseI got this question in exam.Question is from The NFA with epsilon-moves to the DFA-2 in division Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT option is (a) True

Easy EXPLANATION: NFA has n then DFA has at MAX 2^n.

28.

Here is a context-free grammar G: S → AB A → 0A1 | 2 B → 1B | 3A which of the following strings are in L (G)?(a) 021300211(b) 022111300211(c) None of the mentioned(d) 021300211 & 022111300211This question was addressed to me during an internship interview.My question is based upon The NFA with n-moves to the DFA in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct option is (d) 021300211 & 022111300211

The BEST explanation: First, notice that A generates strings of the FORM 021, where n is 0 or more. Also, B gives ZERO or more 1’s, which is followed by one 3, and then A gives something. Since S generates something an A can generate followed by something a B can generate, the strings in L (G) are of the form 0 21 30 21.

29.

The number of states in DFA that accepts the language L(M) ∩ L(N) is _________(a) 0(b) 1(c) 2(d) 3I had been asked this question in an interview for job.Origin of the question is Obtaining the regular Expression from the Finite automata in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct choice is (b) 1

Easiest explanation: In DFA M: all strings MUST END with ‘a’. In DFA N: all strings must end with ‘b’. So the INTERSECTION is EMPTY. For an empty language, only one state is NEEDED.

30.

What is the output of a lexical analyzer?(a) Machine Code(b) Intermediate Code(c) Stream of Token(d) Parse TreeI have been asked this question during an online interview.This interesting question is from Lexical Analyser in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct option is (c) STREAM of Token

Easy EXPLANATION: The output GIVEN is in the form of tokens.

31.

What goes over the characters of the lexeme to produce value?(a) Scanner(b) Parser(c) Evaluator(d) Lexical generatorThis question was addressed to me at a job interview.The doubt is from Lexical Analyser topic in division Finite Automata and Regular Expression of Compiler

Answer»

The correct ANSWER is (a) Scanner

The explanation: In order to CONSTRUCT a token, the lexical analyzer needs a second stage, the evaluator, which GOES over the characters of the LEXEME to PRODUCE a value.

32.

The length of the shortest string NOT in the language (over Σ = {a, b}) of the following regular expression is _____________a*b*(ba)*a*(a) 2(b) 3(c) 4(d) 5This question was posed to me in an internship interview.My enquiry is from Minimization of DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer»

Right ANSWER is (b) 3

Explanation: baa is not REGULAR so 3.

33.

Which of the following identity is true?(a) Ɛ + RR* = R* = ɛ + R*R(b) (R1R2)*R1 = R1 (R2R1)*(c) R*R* = R*(d) All of the mentionedI got this question in a job interview.This is a very interesting question from Obtaining the regular Expression from the Finite automata in section Finite Automata and Regular Expression of Compiler

Answer» RIGHT option is (d) All of the mentioned

For EXPLANATION I would SAY: The FORMER Re can be produced from the latter one.
34.

What can be said about a regular language L over {a} whose minimal finite state automaton has two states?(a) L must be {an| n is odd}(b) L must be {an| n is even}(c) L must be {an| n is even}(d) Either L must be {an | n is odd}, or L must be {an | n is even}This question was posed to me in an interview.This interesting question is from Obtaining the regular Expression from the Finite automata topic in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct option is (d) Either L must be {an | n is ODD}, or L must be {an | n is even}

Easy EXPLANATION: There are TWO STATES. When first state is final, it accepts even no. of a’s. When second state is final, it accepts odd no. of a’s.

35.

Which of the following is not regular?(a) String whose length is perfect square and consists of 0s(b) Palindromes consistingof 0’s and 1’s(c) String whose length is perfect square and consists of 0s & Palindromes consistingof 0’s and 1’s(d) None of the mentionedThis question was addressed to me in a national level competition.My doubt stems from Obtaining the regular Expression from the Finite automata in portion Finite Automata and Regular Expression of Compiler

Answer»

Correct choice is (c) String whose length is PERFECT square and consists of 0s & Palindromes consistingof 0’s and 1’s

Best explanation: STRINGS of odd numbers of zeros can be generated by regular expression (00)*0.

36.

When expression sum=3+2 is tokenized then what is the token category of 3?(a) Identifier(b) Assignment operator(c) Integer Literal(d) Addition OperatorI got this question in a national level competition.This is a very interesting question from Lexical Analyser in division Finite Automata and Regular Expression of Compiler

Answer»

Right answer is (C) Integer Literal

To ELABORATE: Lexeme

Token CATEGORY

37.

Lexers are often generated by a lexer generator, same as parser generators.(a) True(b) FalseThis question was posed to me in an international level competition.My doubt stems from Lexical Analyser topic in section Finite Automata and Regular Expression of Compiler

Answer»

Right answer is (a) True

The BEST EXPLANATION: Lexers are often generated by a LEXER GENERATOR same as parser.

38.

Which one is a lexer Generator?(a) ANTLR(b) DRASTAR(c) FLEX(d) All of the mentionedThe question was asked in a job interview.Asked question is from Lexical Analyser topic in portion Finite Automata and Regular Expression of Compiler

Answer» CORRECT answer is (d) All of the mentioned

To elaborate: ANTLR – Can GENERATE lexical analyzers and parsers.

DFASTAR – Generates DFA matrix table-driven lexers in C++.

Flex – variant of the “LEX” (C/C++).

Ragel – A state machine and LEXER generator with output in C, C++, C#, Objective-C, D, Java, GO and Ruby.
39.

Input to Lexical Analyser is _________(a) Source Code(b) Object Code(c) Lexeme(d) None of the mentionedThe question was asked in exam.Query is from Lexical Analyser in section Finite Automata and Regular Expression of Compiler

Answer» RIGHT OPTION is (a) SOURCE Code

The BEST explanation: LEXICAL analyser’s Input is Source Code.
40.

The reorganizing capability of NDFA and DFA is?(a) May be different(b) Must be different(c) Must be same(d) None of the mentionedThis question was addressed to me during an interview.This intriguing question comes from Obtaining the regular Expression from the Finite automata topic in section Finite Automata and Regular Expression of Compiler

Answer»

Correct OPTION is (c) Must be same

The EXPLANATION: Given any NDFA ONE can CONSTRUCT an equivalent DFA.

41.

Which grammar is not regular?(a) 0^n(b) 0^n 1^n n(c) 0^m 0^n n(d) 0^n 0^n nThe question was posed to me in quiz.This key question is from The NFA with n-moves to the DFA in division Finite Automata and Regular Expression of Compiler

Answer»

The correct option is (a) 0^n

The BEST I can explain: ACCORDING to pumping lemma, is not a REGULAR language. It is the language of the DFA with two states to ACHIEVE an even NUMBER of 0’s…

42.

The minimum state automation equivalent to the below FSA has the following number of states?(a) 1(b) 2(c) 3(d) 4I had been asked this question by my college professor while I was bunking the class.I'm obligated to ask this question of Minimization of DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer»

Right choice is (b) 2

The EXPLANATION is: STATE q0 can be omitted because it TAKES the same input as state q1 HENCE by removing q0 nothing changes.

 Following is equivalent FSA with 2 states.

43.

__________ a part of a compiler that is responsible for recognizing syntax.(a) Parser(b) Bzr(c) Linker(d) OptimizerThe question was posed to me at a job interview.This interesting question is from The NFA with epsilon-moves to the DFA-2 in division Finite Automata and Regular Expression of Compiler

Answer» RIGHT choice is (a) PARSER

Best explanation: Parser RECOGNISES all the syntax of the LANGUAGE.
44.

If is a language, and is a symbol, then, the quotient of and, is the set of strings such that is in: is in. Suppose is regular, which of the following statements is true?(a) L/a is always a regular language(b) L/a is not a regular language(c) All of the mentioned(d) None of the mentionedI have been asked this question in an internship interview.The above asked question is from The NFA with n-moves to the DFA topic in portion Finite Automata and Regular Expression of Compiler

Answer»

The correct choice is (a) L/a is ALWAYS a REGULAR language

Explanation: We can build a DFA for as such: FIRSTLY we get the DFA for: Then, we copy all the states and transitions to the DFA for. HOWEVER, we mark any state as a final state in if and only if is a final state in.

45.

Ndfa and dfa accept same languages.(a) True(b) FalseI had been asked this question in class test.I need to ask this question from The NFA with epsilon-moves to the DFA-2 in portion Finite Automata and Regular Expression of Compiler

Answer»

The CORRECT CHOICE is (a) True

The EXPLANATION is: They both are EQUIVALENT.

46.

Consider the languages L1 =and L2 = {a}. Which one of the following represents L1 L2* U L1*?(a) €(b) a*(c) All of the mentioned(d) None of the mentionedI have been asked this question in quiz.The doubt is from Minimization of DFA topic in section Finite Automata and Regular Expression of Compiler

Answer» RIGHT CHOICE is (a) €

To ELABORATE: L1* =* which is { }.
47.

Lexical Analysis Identifies Different Lexical Units in a _______(a) Source Code(b) Object Code(c) Lexeme(d) None of the mentionedThis question was addressed to me in unit test.Question is taken from Lexical Analyser topic in division Finite Automata and Regular Expression of Compiler

Answer»

Right OPTION is (a) SOURCE Code

To ELABORATE: Lexical ANALYSIS Identifies DIFFERENT Lexical Units in a source Code.

48.

Lexical Analyser’s Output is given to Syntax Analysis.(a) True(b) FalseI had been asked this question during an interview.My doubt stems from Lexical Analyser in section Finite Automata and Regular Expression of Compiler

Answer» CORRECT answer is (a) True

For EXPLANATION I would say: LEXICAL Analyzer’s Output is given to Syntax ANALYSIS.
49.

DFAs, NFAs, and ε-NFA s are equivalent.(a) True(b) FalseThis question was addressed to me in homework.Origin of the question is The NFA with epsilon-moves to the DFA-2 in chapter Finite Automata and Regular Expression of Compiler

Answer»

Correct ANSWER is (a) True

To EXPLAIN: For every NFA there is an ε-NFA that accepts a similar LANGUAGE and vice VERSA.

50.

Which grammar defines Lexical Syntax?(a) Regular Grammar(b) Syntactic Grammar(c) Context free Grammar(d) Lexical GrammarThe question was posed to me at a job interview.My question is from Lexical Analyser in section Finite Automata and Regular Expression of Compiler

Answer» RIGHT CHOICE is (d) Lexical Grammar

Explanation: The specification of a programming language OFTEN includes a SET of rules, the lexical grammar, which defines the lexical SYNTAX.