A context-free grammar in normal form is a 4-tuple (V, R, S) where:
a) V is a finite set called the variables.
b) R is a finite set, disjoint from V, called the terminals.
c) S ∈ V is the start variable.
d) R is a finite set of rules which may be of the following three forms:
i. ABC
ii. Aa
iii. S → ε, where a is any terminal and A, B, C are any variables, except that BS and CS.
If u and v ∈ V*, we say that u = v if there exists a series of applications of rules of R: u = u1 → u2 → ... → un = v, such that each step ui → ui+1 consists of replacing some variable in the string u according to a rule in R. The language generated by the grammar is {u ∈ V* : S = u}. A language which can be expressed in this way is known as a context-free language.
Show that for any context-free grammar given in the above normal form, there is an algorithm to determine membership in the language generated by the grammar, which runs in time O(n^3) on strings of length n.