Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis) or Postfix? State with reason..
I only could tell them that:
Please throw some light on whether I am right on this?
Infix expression is an expression in which the operator is in the middle of operands, like operand operator operand. Postfix expression is an expression in which the operator is after operands, like operand operator. Postfix expressions are easily computed by the system but are not human readable.
Postfix expression is simple to execute as a comparison to the infix expression it required more operation to execute. In the postfix expression, the overhead of brackets is not there while in the infix expression the overhead of brackets is there.
Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression. Simply of the form (operand1 operator operand2). Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands.
Postfix doesn't require any operator-driven order of operations; it's always explicit. So for a stack-based compiler, it's very easy to implement, and for humans, it's easy to understand the order of operations.
On the other hand, infix doesn't require you to read all the verbs at the end :-P. Humans work on infix or even prefix; "add A to B" makes more sense than "A and B: add them".
But, this question is fundamentally subjective. Postfix will always be better for the computer system, but infix has its merits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With