MCQ Computer Science

Compilers Questions and Answers – Finite Automata and Regular Expressions – 2

This set of Compilers Interview Questions and Answers focuses on “Finite Automata and Regular Expressions – 2”.

 

  1. Which of the following strings is not generated by the following grammar?

S ? SaSbS|e

  1. a) aabb
  2. b) abab
  3. c) aababb
  4. d) aaabbb

“Answer

 

Answer: d

Explanation:

S->aSbS putting S-> € and then S->SaSbS

S->aSaSaSbSbSbS putting S->SaSbS

S->aaabbb putting S->€.

  1. Regular expressions can be used only for values of type string and number.
  2. a) True
  3. b) False

Answer

 

Answer: b

Explanation: RE is used for all types of string and numbers.

  1. What is the Regular Expression Matching Zero or More Specific Characters
  2. a) x
  3. b) #
  4. c) *
  5. d) &

Answer

 

Answer: c

Explanation: Zero or Specific Expression matching can be done only by a single character that is*.

  1. All __________ are automatically treated as regular expressions.
  2. a) Programmatic description
  3. b) Window
  4. c) Win Object
  5. d) Collection

“Answer

 

Answer: a

Explanation: It is seen that programmatic description are treated as regular expression.

  1. Regular Expressions can be used with XML checkpoints.
  2. a) True
  3. b) False

Answer

 

Answer: a

Explanation: XML checkpoints employ RE.

  1. The production Grammar is {S->aSbb,S->abb} is
  2. a) Type-3 grammar
  3. b) Type-2 grammar
  4. c) Type-1 grammar
  5. d) Type-0 grammar

Answer

 

Answer: b

Explanation: As per the definition of type-2 grammar.

  1. Regular expression (x/y)(x/y) denotes the set
  2. a) {xy,xy}
  3. b) {xx,xy,yx,yy}
  4. c) {x,y}
  5. d) {x,y,xy}

Answer

 

Answer: b

Explanation: From first part if we take x then from the latter part x then it forms xx

From first part if we take x then from the latter part y then it forms xy

From first part if we take y then from the latter part x then it forms yx

From first part if we take y then from the latter part y then it forms yy.

  1. Regular expression x/y denotes the set
  2. a) {x,y}
  3. b) {xy}
  4. c) {x}
  5. d) {y}

Answer

 

Answer: a

Explanation: Because either x or y can be selected.

  1. The regular expressions denote zero or more instances of an x or y is
  2. a) (x+y)
  3. b) (x+y)*
  4. c) (x* + y)
  5. d) (xy)*

Answer

 

Answer: b

Explanation: For instances of x or y the exp is x+y and both can zero or more times than (x+y)*.

10.The regular expression denote a language comprising all possible strings of even length over the alphabet (0, 1)

  1. a) 1 + 0(1+0)*
  2. b) (0+1) (1+0)*
  3. c) (1+0)
  4. d) (00+0111+10)*

Answer

 

Answer: d

Explanation: Option A does not consider even length criteria for the question.

Option B it can so happen here that from the former bracket it takes 0 or 1 and takes null from the latter then it forms a string of odd length

Option C it gives either 1 or 0.

Hence Option D is the answer.

11. The RE gives none or many instances of an x or y is

  1. a) (x+y)
  2. b) (x+y)*
  3. c) (x* + y)
  4. d) (xy)*

Answer

 

Answer: b

Explanation: Whether x or y is denoted by x+y and for zero or more instances it is denoted but (x+y)*.

12. The RE in which any number of 0’s is followed by any number of 1’s followed by any number of 2’s is

  1. a) (0+1+2)*
  2. b) 0*1*2*
  3. c) 0* + 1 + 2
  4. d) (0+1)*2*

Answer

 

Answer: b

Explanation: The order for the desired string is 012 and foe any number of 0s we write 0* for any number of 1s we denote it by 1* and similarly for 2*.Thus 0*1*2*.

13. The regular expression have all strings of 0’s and 1’s with no two consecutive 0’s is :

  1. a) (0+1)
  2. b) (0+1)*
  3. c) (0+?) (1+10)*
  4. d) (0+1)* 011

Answer

 

Answer: c

Explanation: From the former bracket we choose 0 or epsilon. Then from the latter part 1 or 10 which can be followed by 1 or 10.

14. The regular expression with all strings of 0’s and 1’s with at least two consecutive 0’s is:

  1. a) 1 + (10)*
  2. b) (0+1)*00(0+1)*
  3. c) (0+1)*011
  4. d) 0*1*2*

Answer

 

Answer: b

Explanation: The expression (0+1)*00(0+1)* is where either it initially takes 0 or 1 or 00 followed by string of combination of 0 and 1.

15. Which of the following is NOT the set of regular expression R = (ab + abb)* bbab

  1. a) ababbbbab
  2. b) abbbab
  3. c) ababbabbbab
  4. d) abababab

Answer

 

Answer: a

Explanation: ab followed by abb which is followed by bbab.

16. String generated by

S->aS/bA,

A->d/ccA

  1. a) aabccd
  2. b) adabcca
  3. c) abcca
  4. d) abababd

Answer

 

Answer: a

Explanation: S->aS (substitute S->aS)

S->aaS (substitute S->bA)

S->aabA (substitute A->ccA)

S->aabccA (substitute A->d)

S->aabccd.

17. Consider the production of the grammar S->AA A->aa A->bb Describe the language specified by the production grammar.

  1. a) L = {aaaa,aabb,bbaa,bbbb}
  2. b) L = {abab,abaa,aaab,baaa}
  3. c) L = {aaab,baba,bbaa,bbbb}
  4. d) L = {aaaa,abab,bbaa,aaab}

Answer

 

Answer: a

Explanation: S->AA (substitute A->aa)

S->aaaa

S->AA (substitute A->aa )

S->aaA (substitute A->bb)

S->aabb

S->AA (substitute A->bb the A->aa)

S->bbaa

S->AA (substitute A->bb)

S->bbbb.

18. If R is regular language and Q is any language (regular/ non regular), then Pref (Q in R) is _____________

  1. a) Non-regular
  2. b) Equal
  3. c) Infinite
  4. d) Regular

Answer

 

Answer: d

Explanation: So says the definition of Regular Grammar.

19. The production of the form no terminal ? ? is said to be null production.

  1. a) False
  2. b) True

Answer

 

Answer: b

Explanation: Here the non terminal that gives null will said to have a null production.

 

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close

Adblock Detected

Please consider supporting us by disabling your ad blocker