Time and Space Complexity of Top-down Parsing
When top-down parser tries to parse an ambiguous input with respect to an ambiguous CFG, it may need exponential number of steps (with respect to the length of the input) to try all alternatives of the CFG in order to produce all possible parse trees, which eventually would require exponential memory space. The problem of exponential time complexity in top-down parsers constructed as sets of mutually recursive functions has been solved by Norvig in 1991. His technique is similar to the use of dynamic programming and state-sets in Earley's algorithm (1970), and tables in the CYK algorithm of Cocke, Younger and Kasami.
The key idea is to store results of applying a parser p at position j in a memotable and to reuse results whenever the same situation arises. Frost, Hafiz and Callaghan also use memoization for refraining redundant computations to accommodate any form of CFG in polynomial time (Θ(n4) for left-recursive grammars and Θ(n3) for non left-recursive grammars). Their top-down parsing algorithm also requires polynomial space for potentially exponential ambiguous parse trees by 'compact representation' and 'local ambiguities grouping'. Their compact representation is comparable with Tomita’s compact representation of bottom-up parsing.
Using PEG's, another representation of grammars, packrat parsers provide an elegant and powerful parsing algorithm. See Parsing expression grammar.
Read more about this topic: Top-down Parsing
Famous quotes containing the words time and space, time and, time, space and/or complexity:
“It is only in the world of objects that we have time and space and selves.”
—T.S. (Thomas Stearns)
“The personal things should be left out of platforms at conventions .... You can argue yourself blue in the face, and youre not going to change each others minds. Its a waste of your time and my time.”
—Barbara Bush (b. 1925)
“And time brings down what is both strong and tall.
But plants new set to be eradicate,
And buds new blown, to have so short a date,
Is by his hand alone that guides nature and fate.”
—Anne Bradstreet (c. 16121672)
“In the United States there is more space where nobody is is than where anybody is.”
—Gertrude Stein (18741946)
“The price we pay for the complexity of life is too high. When you think of all the effort you have to put intelephonic, technological and relationalto alter even the slightest bit of behaviour in this strange world we call social life, you are left pining for the straightforwardness of primitive peoples and their physical work.”
—Jean Baudrillard (b. 1929)