All Exams  >   Computer Science Engineering (CSE)  >   Theory of Computation  >   All Questions

All questions of Context Free Grammar, Languages and Push Down Automata for Computer Science Engineering (CSE) Exam

If a Context Free Grammar G is in Chomsky Normal Form, to derive a string of length 101 number of productions needed is _____.
    Correct answer is '201'. Can you explain this answer?

    Gate Gurus answered
    Concepts:
    A context-free grammar is in Chomsky Normal Form if all productions are of the form
    A → BC or A → a
    {A, B, C} ϵ V and a ϵ T
    V is variable(non-terminal) and a is terminal
    Data:
    x = 101
    n → number of productions required to generates string of length x.
    Formula:
    n = 2x – 1
    where x is the length of the string
    Calculation:
    n = 2(101) – 1
    ∴ n = 201

    One of the uses of CNF is to turn parse tree into:
    • a)
      AVL trees
    • b)
      Binary search trees
    • c)
      Binary trees
    • d)
      None of the above
    Correct answer is option 'C'. Can you explain this answer?

    Devika Kaur answered


    Converting Parse Tree into Binary Trees using CNF:

    Parsing is a process in which a program takes input in the form of a sequence of tokens and converts it into a hierarchical structure that reflects the grammar rules of a language. One common representation of this hierarchical structure is a parse tree.

    Chomsky Normal Form (CNF):

    Chomsky Normal Form (CNF) is a specific form of context-free grammar where every production rule is of the form A -> BC or A -> a, where A, B, and C are non-terminal symbols and 'a' is a terminal symbol. CNF simplifies the process of parsing and manipulation of context-free grammars.

    Converting Parse Tree into Binary Trees:

    - Parse Tree: A parse tree is a graphical representation of the syntax of a language. Each node in the tree represents a symbol in the grammar, and the edges represent the relationships between the symbols.

    - Binary Tree: In a binary tree, each node has at most two children, typically referred to as the left child and the right child. This structure is well-suited for representing hierarchical relationships.

    - Conversion Process: By transforming a parse tree into a binary tree using CNF, we can simplify the tree structure and make it easier to analyze and manipulate. This conversion involves restructuring the nodes and edges of the parse tree to adhere to the rules of a binary tree.

    - Benefits: Converting a parse tree into a binary tree using CNF can help in various tasks such as syntax analysis, semantic analysis, and code generation in compilers. The binary tree representation simplifies the process of traversing and processing the hierarchical structure of the parse tree.

    In conclusion, the use of CNF to convert a parse tree into a binary tree provides a structured and efficient way to represent the syntax of a language, making it easier to perform various operations in the context of language processing.

    If L(G) is accepted by pushdown automaton and x is a string of length 21 in L(G), how long is a derivative of x in G, if G is Chomsky normal form?
    • a)
      40
    • b)
      41
    • c)
      42
    • d)
      39
    Correct answer is option 'B'. Can you explain this answer?

    Sudhir Patel answered
    Chomsky normal form
    S → AB
    A → a
    B → b
    Length of string = |x|
    Length of the derivate of string x in context free grammar:
    2|x| – 1 = 2 × 21 - 1 = 41
    Note:
    Question say steps needed to generated string of 10 length
    e.g. if we need to generate ab (string of length 2)
    S → AB
    S → aB
    S → ab
    Number of steps = 2× 2 – 1 = 3

    To obtain a string of n Terminals from a given Chomsky normal form grammar, the number of productions to be used is:
    • a)
      2n − 1
    • b)
      2n
    • c)
      n + 1
    • d)
      n2
    Correct answer is option 'A'. Can you explain this answer?

    The correct answer is b) 2n-1.

    In Chomsky normal form grammar, all productions are of the form A -> BC or A -> a, where A, B, and C are non-terminals and a is a terminal.

    To obtain a string of n terminals, we need to use n-1 productions of the form A -> BC and one production of the form A -> a.

    Therefore, the total number of productions needed is (n-1) + 1 = n.

    Let G = (V, T, S, P) be any context-free grammar without any λ-productions or unit productions. Let K be the maximum number of symbols on the right of any production in P. The maximum number of production rules for any equivalent grammar in Chomsky normal form is given by:
    Where |⋅| denotes the cardinality of the set.
    • a)
      (K - 1)|P| + |T| -1
    • b)
      (K - 1)|P| + |T|
    • c)
      K |P| + |T| -1
    • d)
      K |P| + |T|
    Correct answer is option 'B'. Can you explain this answer?

    Megha Yadav answered
    Restrictions on its production rules. Here, V represents the set of variables (non-terminals), T represents the set of terminals, S represents the start symbol, and P represents the set of production rules.

    A context-free grammar is a formal grammar in which every production rule has exactly one variable on the left-hand side. This means that the left-hand side of each production rule can be replaced by any sequence of variables and terminals.

    The absence of any restrictions on the production rules means that they can be of any form and can have any number of variables and terminals on both sides. However, it is important to note that there are certain conventions and common practices followed in defining and using context-free grammars.

    For example, in a context-free grammar, the start symbol S is usually a single variable and the production rules are typically defined in a specific format. Each production rule has a single variable on the left-hand side and a sequence of variables and terminals on the right-hand side. The production rules are used to generate valid strings in the language defined by the grammar.

    In summary, a context-free grammar without any restrictions on its production rules can have any form of rules, but it is common to follow certain conventions and practices in order to define and use the grammar effectively.

    Which of the following grammar is in Greibach Normal Form?
    A. S → AB, A → a, B → b
    B. S → aA | A → ϵ
    C. S → Aa, A → a
    • a)
      Only A and B
    • b)
      Only B and C
    • c)
      A, B and C
    • d)
      None of these
    Correct answer is option 'D'. Can you explain this answer?

    Sudhir Patel answered
    A context grammar is said to be in Greibech Normal Form if all the productions have the form
    S → xA
    where x ϵ T and x ϵ V*
    T is terminal and V is variable (non-terminal)
    • Option A: Not in GNF. Since production S → AB is not in GNF
    • Option B: Not in GNF. Since production A → ϵ is not in GNF
    • Option C: Not in GNF. Since production S → Aa is not in GNF

    Which of the following regular expression allows strings on {a,b}* with length n where n is a multiple of 4.
    • a)
      (a+b+ab+ba+aa+bb+aba+bab+abab+baba)*
    • b)
      (bbbb+aaaa)*
    • c)
      ((a+b)(a+b)(a+b)(a+b))*
    • d)
      None of the mentioned
    Correct answer is option 'C'. Can you explain this answer?

    Krithika Gupta answered

    Explanation:

    Regular Expression Explanation:
    - The regular expression ((a+b)(a+b)(a+b)(a+b))* matches strings of length n where n is a multiple of 4.
    - Each (a+b) in the regular expression represents a single character from the set {a, b}.
    - Since there are four (a+b) groups in the regular expression, it ensures that the string length is a multiple of 4.

    Option Analysis:
    - Option (a) includes multiple combinations of a and b but does not specifically require the length to be a multiple of 4.
    - Option (b) only allows strings consisting of only 'a's or 'b's, which does not cover all possible strings with length n being a multiple of 4.
    - Option (c) is the correct choice as it enforces the condition of having the string length as a multiple of 4 by repeating the (a+b) group four times.

    Therefore, the correct regular expression that allows strings on {a,b}* with length n where n is a multiple of 4 is option (c) ((a+b)(a+b)(a+b)(a+b))*.

    Which of the following are non essential while simplifying a grammar?
    • a)
      Removal of useless symbols
    • b)
      Removal of unit productions
    • c)
      Removal of null production
    • d)
      None of the mentioned
    Correct answer is option 'D'. Can you explain this answer?

    Rajesh Malik answered
    Here are some process used to simplify a CFG but to produce an equivalent grammar:
    a) Removal of useless symbols(non terminal) b) Removal of Unit productions and c) Removal of Null productions.

    The context free grammar which generates a Regular Language is termed as:
    • a)
      Context Regular Grammar
    • b)
      Regular Grammar
    • c)
      Context Sensitive Grammar
    • d)
      None of the mentioned
    Correct answer is option 'B'. Can you explain this answer?

    Subham Saha answered
    Regular grammar is a subset of Context free grammar. The CFGs which produces a language for which a finite automaton can be created is called Regular grammar.

    The instantaneous PDA is has the following elements
    • a)
      State
    • b)
      Unconsumed input
    • c)
      Stack content
    • d)
      All of the mentioned
    Correct answer is option 'D'. Can you explain this answer?

    Aman Menon answered
    The instantaneous description of a PDA is represented by 3 tuple:
    (q,w,s)
    where q is the state, w is the unconsumed input and s is the stack content.

    The following move of a PDA is on the basis of:
    • a)
      Present state
    • b)
      Input Symbol
    • c)
      Both (a) and (b)
    • d)
      None of the mentioned
    Correct answer is option 'C'. Can you explain this answer?

    Rishika Pillai answered
    The next operation is performed by PDA considering three factors: present state,symbol on the top of the stack and the input symbol.

    Which of the following strings is not generated by the given grammar:S->SaSbS|e
    • a)
      aabb
    • b)
      abab
    • c)
      abaabb
    • d)
      None of the mentioned
    Correct answer is option 'D'. Can you explain this answer?

    Megha Dasgupta answered
    All the given options are generated by the given grammar. Using the methods of left and right derivations, it is simpler to look for string which a grammar can generate.

    Which among the following cannot be accepted by a regular grammar?
    • a)
      L is a set of numbers divisible by 2
    • b)
      L is a set of binary complement
    • c)
      L is a set of string with odd number of 0
    • d)
      L is a set of 0n1n
    Correct answer is option 'D'. Can you explain this answer?

    There exists no finite automata to accept the given language i.e. 0n1n. For other options, it is possible to make a dfa or nfa representing the language set.

    A Non-Regular Grammar 
    may or may not produce a Regular Language

    Hence, the correct answer is Option D

    You can go through more such questions by going through the link:

    Which of the following gives a positive result to the pumping lemma restrictions and requirements?
    • a)
      {aibici|i>=0}
    • b)
      {0i1i|i>=0}
    • c)
      {ss|s∈{a,b}*}
    • d)
      None of the mentioned
    Correct answer is option 'B'. Can you explain this answer?

    Nandini Mehta answered
    Unfortunately, there is a typo in the question and the word after "i" is missing. Please provide the complete regular expression so that I can answer your question accurately.

    The pumping lemma is often used to prove that a language is:
    • a)
      Context free
    • b)
      Not context free
    • c)
      Regular
    • d)
      None of the mentioned
    Correct answer is option 'B'. Can you explain this answer?

    Amrutha Singh answered
    The pumping lemma is often used to prove that a given language L is non-context-free, by showing that arbitrarily long strings s are in L that cannot be “pumped” without producing strings outside L.

    What is the minimum number of productions present in the below given context free grammar to make it Chomsky Normal Form?
    S → XYx
    X → xxy
    Y → Xz
    • a)
      7
    • b)
      8
    • c)
      9
    • d)
      10
    Correct answer is option 'B'. Can you explain this answer?

    Sudhir Patel answered
    Concepts:
    A context-free grammar is in Chomsky Normal Form if all productions are of the form
    A → BC or A → a
    {A, B, C} ϵ V and a ϵ T
    V is variable(non-terminal) and a is terminal
    Calculation:
    S → XA
    A → YB
    B → x
    X → BC
    C → BD
    D → y
    Y → XE
    E → z

     What is the pumping length of string of length x?
    • a)
      x+1
    • b)
      x
    • c)
      x-1
    • d)
      x2
    Correct answer is option 'A'. Can you explain this answer?

    Rishabh Sharma answered
    There exists a property of all strings in the language that are of length p, where p is the constant-called the pumping length .For a finite language L, p is equal to the maximum string length in L plus 1.

    Choose the correct option:
    Statement 1: Recursive Inference, using productions from head to body.
    Statement 2: Derivations, using productions from body to head.
    • a)
      Statement 1 is true and Statement 2 is true
    • b)
      Statement 1 and Statement 2, both are false
    • c)
      Statement 1 is true and Statement 2 is false
    • d)
      Statement 2 is true and Statement 1 is true
    Correct answer is option 'B'. Can you explain this answer?

    Nishtha Gupta answered
    Understanding the Statements
    The statements provided pertain to the concepts of Recursive Inference and Derivations in formal systems, particularly in logic and programming languages.
    Statement 1: Recursive Inference
    - This statement claims that Recursive Inference operates by using productions from head to body.
    - In formal systems, the correct approach is to derive conclusions or infer information by applying rules to the body (the conditions) to reach the head (the conclusion).
    - Thus, this statement is incorrect.
    Statement 2: Derivations
    - This statement posits that Derivations use productions from body to head.
    - Derivation typically involves starting with premises (the body) and applying inference rules to arrive at a conclusion (the head).
    - This statement is correct as it aligns with standard derivational processes in logic.
    Evaluation of the Statements
    - Given that Statement 1 is false and Statement 2 is true, the combined evaluation leads us to conclude that both statements cannot be true simultaneously.
    - Therefore, the correct option is that both statements are false, which corresponds to option 'B'.
    Conclusion
    - In summary, Recursive Inference does not function as described in Statement 1, and while Derivations do follow the correct process outlined in Statement 2, it is misrepresented in its relation to the production rules.
    - Hence, option 'B' is justified as both statements being false.

    A null production can be referred to as:
    • a)
      String
    • b)
      Symbol
    • c)
      Word
    • d)
      All of the mentioned
    Correct answer is option 'A'. Can you explain this answer?

    Introduction:
    In the context of formal languages and grammars, a null production refers to a production rule that produces an empty string or epsilon (∈). In other words, it is a production rule that does not generate any symbols.

    Explanation:
    In formal language theory, a production rule is a statement that describes how a nonterminal symbol can be replaced by a sequence of symbols. It is commonly used in the context of context-free grammars (CFGs) and production systems.

    A null production is a production rule where the right-hand side of the rule is an empty string. This means that when the nonterminal symbol on the left-hand side is expanded, it can be replaced with nothing.

    Example:
    Let's consider a simple CFG with two production rules:
    1. S → AB
    2. A → ε

    In this example, the nonterminal symbol S can be expanded to AB, and A can be expanded to an empty string. So, when the production rule A → ε is applied, the symbol A is replaced with nothing, resulting in the null production A → ε.

    Identification:
    - Null productions can be identified by checking the right-hand side of production rules. If the right-hand side is an empty string, it is a null production.

    Significance:
    Null productions have several implications in formal language theory and parsing algorithms:
    - They can influence the derivation of strings in a grammar. For example, if a nonterminal has a null production, it can be expanded to an empty string, affecting the overall structure of the generated strings.
    - They can impact the construction of parse trees during parsing algorithms, as null productions can introduce ambiguity and multiple possible derivations.

    Conclusion:
    In summary, a null production refers to a production rule in formal language theory where the right-hand side of the rule is an empty string. It is significant in the context of formal languages and grammars, influencing the derivation of strings and the construction of parse trees.

    The moves in the PDA is technically termed as:
    • a)
      Turnstile
    • b)
      Shifter
    • c)
      Router
    • d)
      None of the mentioned
    Correct answer is option 'A'. Can you explain this answer?

    Raghav Basu answered
    Turnstile:
    A turnstile is a term used to describe the moves in a Pushdown Automaton (PDA). In a PDA, a turnstile represents a transition from one state to another based on the input symbol and the symbol at the top of the stack.

    Explanation:
    - In a PDA, the turnstile move involves reading an input symbol, popping a symbol from the top of the stack, and pushing a new symbol onto the stack based on the current state of the automaton.
    - The turnstile move allows the PDA to change its state and manipulate the stack contents according to the rules defined by the transition function.

    Importance of Turnstile:
    - The turnstile move is crucial in defining the behavior of a PDA and determining whether a given input string is accepted or rejected by the automaton.
    - By making turnstile moves, the PDA can effectively simulate the processing of context-free languages.

    Conclusion:
    In conclusion, the moves in a PDA are technically termed as turnstile moves. These moves play a vital role in the operation of a Pushdown Automaton and are essential for recognizing context-free languages.

    Let G be a Context Free Grammar in Chomsky Normal Form. To derive a string (aaaaaa)n where a is terminal variable and n is 5, the number of products to be used is _____.
      Correct answer is '59'. Can you explain this answer?

      Pankaj Patel answered
      Solution:

      Chomsky Normal Form of a Context Free Grammar allows only two types of productions:

      1. A → BC
      2. A → a

      where A, B, and C are non-terminal variables and a is a terminal variable.

      To derive a string (aaaaaa)n where a is terminal variable and n is 5, we can follow the following steps:

      Step 1: Start with the start variable S and apply the production S → AB where A and B are two new variables.

      Step 2: Apply the production A → a and B → CD where C and D are two new variables.

      Step 3: Apply the production C → a and D → EF where E and F are two new variables.

      Step 4: Apply the production E → a and F → GH where G and H are two new variables.

      Step 5: Apply the production G → a and H → IJ where I and J are two new variables.

      Step 6: Apply the production I → a and J → a.

      Step 7: Repeat steps 5 and 6 n-1 times to get the string (aaaaaa)n.

      So, to derive the string (aaaaaa)5, we need to use a total of 59 productions.

      Therefore, the correct answer is '59'.

       Production Rule: aAb->agb belongs to which of the following category?
      • a)
        Regular Language
      • b)
        Context free Language
      • c)
        Context Sensitive Language
      • d)
        Recursively Ennumerable Language
      Correct answer is option 'C'. Can you explain this answer?

      Abhijeet Mehta answered
      Context Sensitive Language or Type 1 or Linearly Bounded Non deterministic Language has the production rule where the production is context dependent i.e. aAb->agb.

      Context free grammar is called Type 2 grammar because of ______________ hierarchy.
      • a)
        Greibach
      • b)
        Backus
      • c)
        Chomsky
      • d)
        None of the mentioned
      Correct answer is option 'C'. Can you explain this answer?

      Shounak Yadav answered
       Chomsky hierarchy decide four type of language :Type 3- Regular Language, Type 2-Context free language, Type 1-Context Sensitive Language, Type 0- Unrestricted or Recursively Ennumerable language.

       If the PDA does not stop on an accepting state and the stack is not empty, the string is 
      • a)
        rejected
      • b)
        goes into loop forever
      • c)
        both (a) and (b)
      • d)
        none of the mentioned
      Correct answer is option 'A'. Can you explain this answer?

      Manasa Dey answered
      To accept a string, PDA needs to halt at an accepting state and with a stack empty, else it is called rejected. Given a PDA M, we can construct a PDA M’ that accepts the same language as M, by both acceptance criteria.

      Let L be a CFL. Then there is an integer n so that for any u that belong to language L satisfying
      |t|>=n, there are strings u, v, w, x, y and z satisfying
      t=uvwxy.
      Let p be the number of variables in CNF form of the context free grammar. The value of n in terms of p :
      • a)
        2p
      • b)
        2p
      • c)
        2p+1
      • d)
        p2
      Correct answer is option 'C'. Can you explain this answer?

      Explanation:

      Given Information:
      - Let L be a CFL.
      - There is an integer n such that for any u belonging to language L satisfying |t| >= n, there are strings u, v, w, x, y, and z satisfying t = uvwxy.
      - Let p be the number of variables in CNF form of the context-free grammar.

      Understanding the Relationship:
      - In a CFL, there exists a pumping lemma that states for any string u in the language L with length at least n, we can divide u into five substrings u, v, w, x, and y such that uv^iwx^iy is also in L for all i >= 0.
      - In CNF form of a CFG, each production rule has the form A -> BC or A -> a, where A, B, and C are variables and a is a terminal symbol.

      Finding the Value of n in terms of p:
      - In CNF form, each production rule introduces 2 variables.
      - Therefore, to generate a string of length n, we need at least n/2 production rules.
      - Since p is the total number of variables in CNF form, the minimum value of n occurs when n/2 = p.
      - Solving for n, we get n = 2p.
      Therefore, the value of n in terms of p is 2p+1, which corresponds to option 'C'.

      Chapter doubts & questions for Context Free Grammar, Languages and Push Down Automata - Theory of Computation 2025 is part of Computer Science Engineering (CSE) exam preparation. The chapters have been prepared according to the Computer Science Engineering (CSE) exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

      Chapter doubts & questions of Context Free Grammar, Languages and Push Down Automata - Theory of Computation in English & Hindi are available as part of Computer Science Engineering (CSE) exam. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.

      Theory of Computation

      18 videos|70 docs|44 tests

      Signup to see your scores go up within 7 days!

      Study with 1000+ FREE Docs, Videos & Tests
      10M+ students study on EduRev