All Exams Test series for 1 year @ ₹349 only
Question

Which of the following Grammars is/are only Context Free?
AS $\rightarrow$ Ab
aS$\rightarrow$ aA
A$\rightarrow$ a
BS $\rightarrow$ Ab
A $\rightarrow$ Sa
A $\rightarrow$ a
CS $\rightarrow$ AS
S $\rightarrow$ aA
A$\rightarrow$ a
DS $\rightarrow$ Ab
S $\rightarrow$ aA
A$\rightarrow$ a
ES $\rightarrow$ Sb
A $\rightarrow$ Aa
A $\rightarrow$ $\varepsilon$

Choose the correct answer from the options given below:

The correct answer is
A, B Only

CFG Definition: Context-Free Grammars Explained

A Context-Free Grammar (CFG) is a formal system used to describe languages. Its production rules define how strings can be generated. Each rule in a CFG must follow this specific format:

$A \rightarrow \gamma$

In this notation, $A$ is a single non-terminal symbol (a variable), and $\gamma$ represents any sequence that can include terminals (the actual characters of the language) and/or non-terminal symbols. Regular Grammars are a subset of Context-Free Grammars, meaning all regular grammars are also context-free, but not all context-free grammars are regular.

The question asks us to identify which grammars among the options are '*only* Context Free'. This requires a careful examination of each grammar's structure to determine its classification.

Grammar Structure Analysis

Grammar A Analysis

  • Productions: $S \rightarrow AbA$, $A \rightarrow a$, $B \rightarrow a$
  • Explanation: All the production rules given for Grammar A fit the fundamental definition of a Context-Free Grammar because they all have a single non-terminal on the left side of the arrow ($S$, $A$, $B$). Specifically, the rule $S \rightarrow AbA$ involves non-terminals ($A$ and $B$) appearing on both sides of the production string, with terminals ($b$) in between. This structure means Grammar A is a Context-Free Grammar but does not meet the requirements to be classified as a Regular Grammar.
  • Type: Context-Free Grammar (not a Regular Grammar)

Grammar B Analysis

  • Productions: $S \rightarrow aA$, $A \rightarrow a$
  • Explanation: Grammar B also adheres to the definition of a Context-Free Grammar, as all productions have a single non-terminal on the left. Furthermore, the productions $S \rightarrow aA$ (terminal followed by non-terminal) and $A \rightarrow a$ (terminal) align perfectly with the definition of a Right-Linear Regular Grammar.
  • Type: Regular Grammar (and therefore also a Context-Free Grammar)

Grammar C Analysis

  • Productions: $S \rightarrow ASS$, $A \rightarrow a$
  • Explanation: This grammar is Context-Free because all its rules have a single non-terminal on the left ($S$ or $A$). However, the production rule $S \rightarrow ASS$ includes multiple non-terminals ($A$, $S$, $S$) on the right-hand side. This characteristic makes Grammar C a Context-Free Grammar, but it disqualifies it from being a Regular Grammar.
  • Type: Context-Free Grammar (not a Regular Grammar)

Grammar D Analysis

  • Productions: $S \rightarrow Ab$, $A \rightarrow a$
  • Explanation: All productions in Grammar D satisfy the Context-Free Grammar condition (single non-terminal on the left). The rules $S \rightarrow Ab$ (non-terminal followed by terminal) and $A \rightarrow a$ fit the pattern of a Left-Linear Regular Grammar.
  • Type: Regular Grammar (and therefore also a Context-Free Grammar)

Grammar E Analysis

  • Productions: $S \rightarrow Sb$, $A \rightarrow aA$, $A \rightarrow \varepsilon$
  • Explanation: Grammar E is Context-Free as all its rules start with a single non-terminal. The productions $S \rightarrow Sb$ (non-terminal followed by terminal), $A \rightarrow aA$ (terminal followed by non-terminal), and $A \rightarrow \varepsilon$ (empty string derivation) are all characteristic structures found in Right-Linear Regular Grammars.
  • Type: Regular Grammar (and therefore also a Context-Free Grammar)

Final Selection

Based on the standard definitions, all five grammars (A, B, C, D, E) are indeed Context-Free Grammars. Grammars B, D, and E are specifically classified as Regular Grammars, which is a tighter classification within CFGs. Grammars A and C are Context-Free Grammars that are not Regular Grammars.

The question asks for grammars that are '*only* Context Free', and the provided correct answer indicates 'A, B Only'. This suggests a specific interpretation is intended:

  • Grammar A is selected because it's a CFG that is not a Regular Grammar.
  • Grammar B is selected because it's a Regular Grammar (and thus also CFG).
  • Grammars C, D, and E are excluded. Grammar C is excluded despite also being a CFG but not Regular, and Grammars D and E are excluded despite being Regular Grammars. The exact criteria for this specific selection (A and B only) are not standard but implied by the answer choice.

Therefore, aligning with the provided correct answer, Grammars A and B are identified as fitting the question's criteria.

Was this answer helpful?

Important Questions from Context Free Grammars

  1. Which of the following grammars is (are)ambiguous ?
    (1) S → SS | aSb | bSa |e 

    (2) S → aSbS | bSaS |e 

    (3) S → aAB 

    A → bBb 
    B → A Ι e

  2. Consider the grammar,

    G = S → abScB | e, 

    B→ bB | b. 

    What is the language generated by the given grammar ?

     

  3. Consider the given grammar
    S → Abc | ad 

    A → eS | Cr| ξ 

    C → f/p/ξ
    Compute FIRST (A)

  4. Select the sentence which is meaningful and grammatically correct.

  5. Consider the following context-free grammar $G$.
    $$S \rightarrow abaABabba$$
    $$A \rightarrow aaBBAB \mid bBabaa$$
    $$B \rightarrow aBb \mid ab$$
    In the above grammar, $S$ is the start symbol, $a$ and $b$ are terminal symbols, and $A$ and $B$ are non-terminal symbols.
    Let $L(G)$ be the language generated by the grammar $G$. For a string $s \in L(G)$, let $n_1(s)$ be the number of $a$’s in $s$ and $n_2(s)$ be the number of $b$’s in $s$.
    Which of the following statements is/are true?
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App