Reputation: 777
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?
Upvotes: 5
Views: 8119
Reputation: 3251
The similarity between Infix, Postfix and Prefix:
Differences between Infix, Postfix and Prefix:
Thanks
Upvotes: 0
Reputation: 98529
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.
Upvotes: 9
Reputation: 137890
Memory is not usually an issue here. Compilers spend tons of memory on other things. Postfix usually entails an operand stack, which involves a certain amount of memory (still small) at runtime.
Postfix is useful for low-level interpretable code, such as Java, Forth, Postscript. These all have hardware or super-lightweight software implementations.
Infix is better for readability.
Of course, there's no way to know how the issue affects your field without knowing what kind of job it is.
Upvotes: 1