GATE||Context free language and context free grammar||Pyq(2010to2025)

Last Updated :
Discuss
Comments

Question 1


Consider the following grammars. Names representing terminals have been specified in capital letters.

G1 : stmnt -> WHILE (expr) stmnt

stmnt -> OTHER

expr -> ID

G2 : stmnt -> WHILE (expr) stmnt

stmnt -> OTHER

expr -> expr + expr

expr -> expr * expr

expr -> ID

Which one of the following statements is true?


[GATE || CS || PYQ || 2007]

  • G1 is context-free but not regular and G2 is regular.

  • G2 is context-free but not regular and G1 is regular

  • Both G1 and G2 are regular

  • Both G1 and G2 are context-free but neither of them is regular

Question 2

Let 𝐺1, 𝐺2 be Context Free Grammars (CFGs) and 𝑅 be a regular expression. For a grammar 𝐺, let 𝐿(𝐺) denote the language generated by 𝐺.
Which ONE among the following questions is decidable?

[GATE 2025||SET-2 MCQ|| 1-mark]


  • Is 𝐿(𝐺1 ) = 𝐿(𝐺2 )?

  • Is 𝐿(𝐺1 ) ∩ 𝐿(𝐺2 ) = βˆ…?

  • Is 𝐿(𝐺1 ) = 𝐿(𝑅)?

  • Is 𝐿(𝐺1 ) = βˆ…?

Question 3

Consider two grammars 𝐺1 and 𝐺2 with the production rules given below:
𝐺1: 𝑆 β†’ 𝑖𝑓 𝐸 π‘‘β„Žπ‘’π‘› 𝑆 | 𝑖𝑓 𝐸 π‘‘β„Žπ‘’π‘› 𝑆 𝑒𝑙𝑠𝑒 𝑆 | π‘Ž
𝐸 β†’ 𝑏
𝐺2: 𝑆 β†’ 𝑖𝑓 𝐸 π‘‘β„Žπ‘’π‘› 𝑆 | 𝑀
𝑀 β†’ 𝑖𝑓 𝐸 π‘‘β„Žπ‘’π‘› 𝑀 𝑒𝑙𝑠𝑒 𝑆 | 𝑐
𝐸 β†’ 𝑏
where 𝑖𝑓,π‘‘β„Žπ‘’π‘›,𝑒𝑙𝑠𝑒, π‘Ž, 𝑏, 𝑐 are the terminals.
Which of the following option(s) is/are CORRECT?

[GATE 2025 ||SET-2 MSQ|| 2-mark]


  • 𝐺1 is not 𝐿𝐿(1) and 𝐺2 is 𝐿𝐿(1).

  • 𝐺1 is 𝐿𝐿(1) and 𝐺2 is not 𝐿𝐿(1).

  • 𝐺1 and 𝐺2 are not 𝐿𝐿(1).

  • 𝐺1 and 𝐺2 are ambiguous.

Question 4

Consider a context-free grammar 𝐺 with the following 3 rules.
𝑆 β†’ π‘Žπ‘†, 𝑆 β†’ π‘Žπ‘†π‘π‘†, 𝑆 β†’ 𝑐
Let 𝑀 ∈ 𝐿(𝐺). Let π‘›π‘Ž (𝑀), 𝑛𝑏 (𝑀), 𝑛𝑐 (𝑀) denote the number of times π‘Ž, 𝑏, 𝑐 occur in 𝑀, respectively. Which of the following statements is/are TRUE?

[GATE 2024||SET-2 MSQ|| 1-mark]


  • π‘›π‘Ž(𝑀) > 𝑛𝑏(𝑀)

  • π‘›π‘Ž(𝑀) > 𝑛𝑐 (𝑀) βˆ’ 2

  • 𝑛𝑐(𝑀) = 𝑛𝑏(𝑀) + 1

  • 𝑛𝑐(𝑀) = 𝑛𝑏(𝑀) βˆ— 2

Question 5

Consider the following languages: 

L1 = {ww | w ∈ {a, b}* }

L2 = {anbncm | m, nβ‰₯ 0}

L3 = {ambncn | m, nβ‰₯ 0}

Which of the following statements is/are FALSE?

[GATE 2022|| MSQ|| 1-mark]

  • L1 is not context-free but Land L3 are deterministic context-free.

  • Neither L1 nor L2 is context-free. 

  • L2, L3, and L∩ L3 all are context-free.

  • Neither L1 nor its complement is context-free. 

Question 6

Let L be a context-free language and M a regular language. Then the language is L ∩ M

[GATE || CS || PYQ || 2006 ||]

  • always regular

  • never regular

  • always a deterministic context-free language

  • always a context-free language

Question 7

Consider the languages:

  • L1 = {wwr | w ∈ {0, 1}*}
  • L2 = {w#wr | w ∈ {0, 1}*}, where # is a special symbol
  • L3 = {ww | w ∈ {0, 1}*}

Which one of the following is TRUE?

[GATE || CS || PYQ || 2005]


  • L1 is a deterministic CFL

  • L2 is a deterministic CFL

  • L3 is a CFL, but not a deterministic CFL

  • L3 is a deterministic CFL

Question 8

Let

L1 = {0n+m1n0m | n, m >= 0},

L2 = {0n+m1n+m0m | n, m >= 0} and

L3 = {0n+m1n+m0n+m | n, m >= 0}.

Which of these languages are NOT context free?

[GATE || CS || PYQ || 2006]

  • L1 only

  • L3 only

  • L1 and L2

  • L2 and L3

Question 9

S-> aSa | bSb | a | b

The language generated by the above grammar over the alphabet is the set of:

[GATE || CS || PYQ || 2009]

  • all palindromes

  • all odd length palindromes

  • strings that begin and end with the same symbol

  • all even length palindromes

Question 10

In the context-free grammar below, is the start symbol, and are terminals, and denotes the empty string.

S ->aSAb | ∈

A-> bA | ∈

The grammar generates the language

[GATE || CS || PYQ || 2006]

  • ((a+b)*b)

  • { ambn ∣ m≀n }

  • (ambn | m=n }

  • a*b*

There are 52 questions to complete.

Take a part in the ongoing discussion