i was reading stack and i came across the infix, preifx and postfix expression.So i understood that why postfix /prefix expressions are preferred over infix expression ( due to its unambiguous nature) .But i am not getting any enough information about the popularity reason of postifx expression over prefix expression.

Why are we not using prefix expression than the postfix expression more often?

I am guessing that ,

  1. it's related to the easiness of converting the infix to postfix
  2. or the evaulation process of postifx is easy than prefix.

If so, Please someone elaborate on it.


  • 1
    $\begingroup$ Functional programming languages use prefix. $\endgroup$ – Yuval Filmus Mar 25 at 17:45
  • 2
    $\begingroup$ The only reason I am aware of is, "because HP made a bunch of calculators that used postfix notation." $\endgroup$ – Aaron Rotenberg Mar 25 at 17:48

The evaluation is easier for postfix-notation expressions.

The evaluation is done easily using a stack. The expression is processed from left to right, one token at a time: * operand - put it on the stack; * operator - get from the stack the number of values it needs (two for +, three for ?:, one for unary - and so on), combine the values using the operator and put the result on the stack. * when the entire expression is processed, the stack contains only one value; it is the value of the entire expression.

The prefix-notation expressions can be evaluated using a similar algorithm that uses the operands (instead of the operators) to trigger computations. However, it is not that straight-forward; it involves lookups on the top of the stack to find the operator and to decide if enough operands were read for it.

The prefix-notation expressions can also be evaluated from right to left using the same algorithm as for postfix-notation expressions.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.