The Theorem 7.16 states that every context free languages is a member of class P. The modified algorithm to produce a polynomial time algorithm is as follows,
Modified Algorithm:
“On input and CFG G
repeat for
if parsing is successful for CurrentState
return TREE(CurrentState)
else
if no nodes to expand
return reject
else
PUSH temp into the Parse Tree
if ParseTree is empty
return reject
else
returnParseTree
The above algorithm takes the string and apply the rules on it. For each part of the string rules are applied and the next node is found.
Each state is added to the tree. If the input is processed completely then it returns the parse tree.
Therefore, the modified algorithm has been provided.