0

I know generally how to convert an infix expression into a postfix expression; but I came lately across this quadratic expression: $\left(4y^2 + 2x - 1\right)$ that I had to convert into postfix and it raised a couple of questions for me, namely:

If I have the following expression: $4y^2$ would I treat $4y$ as just one operand or $2$ separate operands? I believe that the postfix equivalent of $4y^2$ would be: 4y2^*

Thank you in advance for clearing this ambiguity for me!

Brian M. Scott
  • 616,228
O.A.
  • 392
  • Why not y2^42x+1-? – nathan.j.mcdougall Nov 02 '14 at 04:04
  • @nathan.j.mcdougall, Because, if I intend to evaluate this expression programatically, using a stack, then I will have to start with the first operand and keep processing the string so that at the end it will look like: 4y2^2x+1- – O.A. Nov 02 '14 at 04:15

2 Answers2

4

The implicit parenthesization of $4y^2$ is $4(y^2)$, so your 4y2^* is correct.

Brian M. Scott
  • 616,228
0

You may find this of interest:

http://en.m.wikipedia.org/wiki/Shunting-yard_algorithm.

The article contains a detailed, generalized description of an algorithm that converts tokenized infix expressions into reverse-Polish.