Context Free Grammars & Languages PYQ QUIZ GATE CS

Last Updated :
Discuss
Comments

Question 1

Consider the languages L1, L2 and L3 as given below.

LI= {0P1q |p, q∈N}

L2={0p1q |p, q∈ N and p=q} and

L3= {0P1q0r |p, q, r∈ N and p =q = r}

Which of the following statements is NOT TRUE?

[GATE | CS | 2011 |]

  • Push Down Automata (PDA) can be used to recognize L1 and L2

  • L1 is a regular language

  • All the three languages are context free

  • Turing machine can be used to recognize all the three languages

Question 2

The grammar S → aSa | bS | c is

  • LL(1) but not LR(1)

  • LR(1)but not LR(1)

  • Both LL(1)and LR(1)

  • Neither LL(1)nor LR(1)

Question 3

Consider the languages - 
L1 = {0i1j | i != j}. 
L2 = {0i1j | i = j}. 
L3 = {0i1j | i = 2j+1}. 
L4 = {0i1j | i != 2j}.

  • Only L2 is context free

  • Only L2 and L3 are context free

  • Only L1 and L2 are context free

  • All are context free

Question 4

Suppose that L1 is a regular language and L2 is a context-free language. Which one of the following languages is NOT necessarily context-free?

  • L1∩L2

  • L1⋅L2

  • L1−L2

  • L1∪L2

Question 5

Consider the following languages.

L1 = { wxyx ∣ w,x,y ∈ (0+1)+ }
L2 = { xy ∣ x,y ∈ (a+b)*, ∣x∣=∣y∣, x≠y }

Which one of the following is TRUE ?

  • L1 is regular and L2 is context- free

  • L1 context- free but not regular and L2 is context-free

  • Neither L1 nor L2 is context- free

  • L1 context- free but L2 is not context-free

Question 6

For a string w, we define wR to be the reverse of w. For example, if w = 01101 then wR = 10110.

Which of the following languages is/are context-free?

  • {wxwRxR ∣ w,x∈{0,1}*}

  • {wwRxxR ∣ w,x∈{0,1}*}

  • {wxwR ∣ w,x∈{0,1}*}

  • {wxxRwR ∣ w,x∈{0,1}*}

Question 7

The language L= {0i21i | i≥0 } over the alphabet {0,1, 2} is:

  • not recursive

  • is recursive and is a deterministic CFL.

  • is a regular language.

  • is not a deterministic CFL but a CFL.

Question 8

 

Here, wr is the reverse of the string w. Which of these languages are deterministic Context-free languages?

  • None of the languages

  • Only L1

  • Only L1 and L2

  • All the three languages

Question 9

Consider the following statements about the context free grammar

G = {S → SS, S → ab, S → ba, S → Ε}
I. G is ambiguous
II. G produces all strings with equal number of a’s and b’s
III. G can be accepted by a deterministic PDA.

Which combination below expresses all the true statements about G?

  • I only

  • I and III only

  • II and III only

  • I, II and III

Question 10

Which one of the following grammars generates the language L = {ai bj | i ≠ j}

 
  • A

  • B

  • C

  • D

There are 32 questions to complete.

Take a part in the ongoing discussion