100% found this document useful (1 vote)
1K views7 pages

CFG MCQ

The document contains 25 multiple choice questions about context free grammars and regular expressions. The questions cover topics such as: the definition of a grammar, what different symbols in a grammar represent, which productions are valid for context free grammars, examples of grammars that generate specific languages, and properties of languages generated by grammars. The answers to each question are also provided.

Uploaded by

shruthi g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views7 pages

CFG MCQ

The document contains 25 multiple choice questions about context free grammars and regular expressions. The questions cover topics such as: the definition of a grammar, what different symbols in a grammar represent, which productions are valid for context free grammars, examples of grammars that generate specific languages, and properties of languages generated by grammars. The answers to each question are also provided.

Uploaded by

shruthi g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

The entity which generate Language is termed as:

a) Automata

b) Tokens

c) Grammar

d) Regular Expressions

Answer: C

2. The Grammar can be defined as: G=(V, ∑, p, S).In the given definition, what does S represents?

a) Accepting State

b) Starting Variable

c) Sensitive Grammar

d) None of these

Answer: B

3. Which of the expression is appropriate for CFG p: A->α where A∈VUT and α ∈_______

a) (VUS)*

b) V

c) (V+Ꞓ)*

d) (V+ T)*

Answer: D

4. For S->0S1|Ꞓ for ∑={0,1}*, which of the following is true for the language produced?

a) Non regular language

b) 0n1n | n>=0

c) 0n1n | n>=1

d) None of the above

Answer: B

5. A->aA| a| b .The number of steps to form aab:

a) 2
b) 3

c) 4

d) 5

Answer: B

6.Which of these does not belong to CFG ?

a. Terminal Symbol

b. Non terminal Symbol

c. Start symbol

d. End Symbol

Answer: D

7.Give a production grammar that specified language L = {an b2n | n>= 1}

a. {S->aSbb,S->abb}

b. {S->aSb, S->b}

c. {S->aA,S->b,A->b}

d. None of the mentioned

Answer: A

8. Identify the production to generate the language with any number of a's and b's with atleast one
b.

a. S->a | aS | bS

b. S->b | aS | bS

c. S->bS | aS

d. S->bS

Answer: B

9.The context free grammar S → SS | 0S1 | 1S0 | ɛ generates

a) Equal number of 0’s and 1’s

b) Unequal number of 0’s and 1’s

c) Any number of 0’s followed by any number of 1’s


d) None of these

Answer: A

10. The CFG S-> aS | bS | a | b is equivalent to___________ regular expression

A. (a + b)

B. (a + b) (a + b)*

C. (a + b) (a + b)

D. None of these

Answer: B

11. Identify the Grammar to generate the Language consisting even number of a's.

A. S-> aS

B. S->aS | Ꞓ

C. S-> aaS

D. S-> aaS | Ꞓ

Answer: D

12. Identify the Grammar to generate the Language consisting any number of a's.

A. S-> aS

B. S->aS | Ꞓ

C. S-> aaS

D. S-> aaS | Ꞓ

Answer: B

13. Context Free language is ________grammar.

A. type-3

B.type-2

C.type-1

D. type-0

Answer: B
14. Identify the Grammar to generate the Language consisting any number of a's or b’s.

A. S-> aS| bS

B. S->a | b

C. S-> aS | bS | a | b

D. S-> aS | bS | Ꞓ

Answer: D

15. Grammar to produce the language L= {w | |w| mod 3=0} where w belongs to ∑*over ∑={a,b}.

A. S->AAAS | Ꞓ

B. S-> |ꞒAAAS, A-> a | b

C. S->AAAS, A-> a |b

D. S->aaaS | bbbS

ANSWER: B

16. Grammar to produce the Regular Expression (a+b)*ab

A. S->Aab, A-> |ꞒaS | bS

B. S->|ꞒaSab | bSab

C. S-> aSab | bSab

D. S->Aab, A-> aA | bA

ANSWER: A

17. Grammar to produce the Regular Expression (a+b)*ab(a+b)*

A. S->AabA, A-> aS | bS

B. S->|ꞒASab | ASab, A->aA | bB

C. S-> aSab | bSab | Ꞓ

D. S->AabA, A-> ꞒaA


| | bA

ANSWER: D

18. Grammar to generate the L= {(01)n |n>=0}


A. S->0S1

B. S->0S1 | 00S11

C. S-> |Ꞓ01

D. None of the above

ANSWER: D

19. Grammar to generate all palindrome strings over ∑={0,1}

A. S->aSa | bSb

B. S-> |ꞒaSa | bSb | a | b

C. S-> |ꞒaSa | bSb | aS | bS

D. Both B & C

ANSWER: B

20. Grammar to generate the Language L={WW R where W belongs to {a,b}*}

A. S->aSa | bSb

B. S->aSb | bSa | Ꞓ

C. S-> aSa | |ꞒbS

D. None of the above

ANSWER: None of the above

m m n
21. Grammar to generate the language L={ 0 1 2 | m>=1 and n>=0}

A. S->AB, A->01 | 01A, B-> |Ꞓ2B

B. S->AB, A->01 | 0A1, B-> |Ꞓ2B

C. S-> |Ꞓ01 | 0S1 | 2B

D. Both A & B

ANSWER: B

22. Grammar to generate the language which contains exactly 2 b’s over ∑={a,b}.

A. S->AbAbA | Ꞓ
B. S->ababa | aS

C. S-> AbAbA, A->aA | Ꞓ

D. None of the above

ANSWER: C

2n
23. Grammar to generate the language L={ a | n>=0 }

A. S->aaS

B. S->aa | Ꞓ

C. S-> aaS | Ꞓ

D. Both A & B

ANSWER: D

24. Grammar to generate the language L= { w | n a(w)mod 2=0 where w belongs to {a,b}* }

A. S-> Ꞓ
| bS | SaSaS

B. S-> bS | SaSaS

C. S->|ꞒbS | aS| SaSaS

D. None of the above

ANSWER: A

25. Grammar is a __________tuples/ Attributes

A. 4

B. 5

C. 7

D. 3

ANSWER: A

You might also like