If is a context free grammar and is a string of length in , how long is a derivation of in , if is in Chomsky normal form?
View worked solution
Answer: C
A Context-Free Grammar (CFG) in Chomsky Normal Form (CNF) has production rules restricted to the following forms:
- (where and are non-terminals)
- (where is a terminal)
Let be a string of length () derived from the start symbol . We can determine the number of steps in the derivation as follows:
- Step 1: Generating non-terminals
We start with a single non-terminal (the start symbol ). Each application of a production rule of the form replaces one non-terminal with two, thereby increasing the total number of symbols in the sentential form by exactly .
To grow the sentential form from symbol to non-terminals, we must apply these rules exactly: - Step 2: Converting non-terminals to terminals
Once we have a sentential form consisting of non-terminals, we must replace each non-terminal with a terminal using rules of the form . Since there are non-terminals, this requires exactly steps:
Adding these together, the total length of the derivation is:
Example:
For a string of length (e.g., ):
- (1 step)
- (2 steps)
- (3 steps)
Free practice · Your answers on this page are not saved.
