recategorized by
4,967 views
16 votes
16 votes
A grammar $G$ is in Chomsky-Normal Form (CNF) if all its productions are of the form $A \to BC$ or $A \to a$, where $A,B$ and $C$, are non-terminals and $a$ is a terminal. Suppose $G$ is a CFG in CNF and $w$ is a string in $L(G)$ of length $n$, then how long is a derivation of $w$ in $G$?
recategorized by

3 Answers

Best answer
34 votes
34 votes

Its answer is $2n-1$ for $n$ length string, because in CNF at every step only $1$ terminal can replace a variable, for example

  • $S\to AB$
  • $A \to a$
  • $B \to c$

For generating string '$ac$' $3$ productions will be used.

Reference:- Peter Linz

edited by
6 votes
6 votes
Let $w=a_1a_2...a_n$... Let's reverse engineer the string.

Each $a_i$ would have converted using $A \rightarrow a$ from a variable adds to $n$ derivation. Further, those variables $V_1V_2...V_n$ would have derived either rightly or leftly using $A \rightarrow BC$ adds to $n-1$ derivation.
2 votes
2 votes
firstly we have to make the required lengh which requires exactly 2n-1 productions becuase we initiallly start with 1 symbol after that convert each variable to terminal using n more productions thus total productions required is n+n-1=2n-1.

Related questions

24 votes
24 votes
4 answers
1
Kathleen asked Oct 4, 2014
5,410 views
Match the following items$$\begin{array}{ll|ll}\hline \text{(i)} & \text{Backus-Naur form} & \text{(a)} & \text{Regular expressions} \\\hline \text{(ii)} & \text{Lexical...
36 votes
36 votes
3 answers
2
Kathleen asked Oct 4, 2014
9,989 views
Which of the following features cannot be captured by context-free grammars?Syntax of if-then-else statementsSyntax of recursive proceduresWhether a variable has been dec...
5 votes
5 votes
0 answers
3
Kathleen asked Oct 5, 2014
1,018 views
Suppose we have a computer with single register and only three instructions given below:$$\begin{array}{ll} \text{LOAD addren} & \text{; load register} \\ \text{} & \te...
3 votes
3 votes
1 answer
4
gatecse asked May 3, 2021
2,401 views
State whether the following statements are True or False with reasons for your answer:A two pass assembler uses its machine opcode table in the first pass of assembly.