How can I estimate the stack space needed to transform an infix expression into...
source link: https://www.codesd.com/item/how-can-i-estimate-the-stack-space-needed-to-transform-an-infix-expression-into-a-postfix-expression.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How can I estimate the stack space needed to transform an infix expression into a postfix expression
There is the famous shunting-yard algorithm that can be used to turn an infix expression (such as 1 + 2 * 3
) into a postfix expression (such as 1 2 2 * +
). The shunting-yard algorithm needs a stack to store elements that are about to be moved.
Is it possible to pre-estimate the length of the stack needed to perform a translation of a specific input into its postfix form in linear time and constant memory?
Sure. The shunting-yard algorithm only pushes operators (including parentheses) onto the stack, so a first-order approximation is the number of operators in the expression. With a little more intelligence, you could scan the expression and look for associativity and grouping. But by the time you were done, you would probably have written a stack-based algorithm for determining the best estimate of the stack size required for the expression, and would have doubled your execution cost.
Related Articles
How can I estimate the size of my gzipped script?
How can I estimate the size of an Oracle index?
How can I get the remaining space for common use in a shell script?
How can I ignore the white space in a Moq VerifySet () expression?
How can I get the free space of a volume in a C program?
How can I estimate the variable influence of factors in my model rather than just factor factors?
How can I set the stack pointer from gdb using JLink and a Cortex M4?
Java - How can I check the next space in a string? (For IRC Bot)
How can I fill the entire space of a 100% div with 3 divs of the same size?
How can I escape the white space in a list of bash loops?
How can I estimate the entropy content of this entry?
How can I estimate the file size of an image using its width and height?
How can I extend the mouse space in OpenGL windowed mode
How can I check the following conditions in c # using a regular expression
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK