Why computers prefer and use Postfix expressions instead of prefix expressions??
Jublee
2006-09-26 10:42:21 UTC
We all know computers convert all infix arihmetic expressions to postfix and then evaluate them.. but why we use and prefer postfix over prefix expressions?
Four answers:
Digitally Й!Й
2006-09-27 11:05:36 UTC
i think implementation of code for sloving postfix expression is easier and solving postfix expressions is much more faster & efficient then solving prefix expressions.
better take a look at this..i think this is the prefix and postfix u were asking about. Both prefix and postfix eliminate ambiguities in evaluation of expressions with different precendence operators.
postfix is preferred over prefix because, the operands are continuously pushed onto stack until an operator is encountered, the values are popped from stack and evaluated, the result is stored back in the stack..this is described better in the lecture at the link i've added. It is a one-pass operation, where u only evaluate based on operator.
in prefix,for similar evaluation, u encounter an operator and then wait for the operands. the operands cud in turn be prefix expressions in which case u r required to remember the past operators(yet to be operated by)..this is a two-pass operation and the techique reduces the ease as opposed to postfix. so postfix is preferred. But prefix also has its own applications, like representing them as functions, or while representing the syntax tree in linear form, starting from root.
?
2016-10-18 04:29:37 UTC
if u want to easily write the answer on a paper, draw the binary tree for above expression and from that write prefix or post fix notation. If u want to jot down a application to get pre or post fix notation. write a application making use of stack.