Quadratic expression into postfix notation

1.6k Views Asked by At

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!

2

There are 2 best solutions below

2
On BEST ANSWER

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

0
On

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.