The Gateway to Computer Science Excellence

+25 votes

+65 votes

Best answer

According to http://faculty.washington.edu/jstraub/dsa/aexp/

The priority of the operators follows the usual conventions:

The highest priority is assigned to unary operators (note that, in this context, a function such assinis considered a unary operator). All unary operators have the same priority. Exponentiation has the second highest priority. The third highest priority is assigned to the multiplication and division operators. The lowest priority is given to the addition and subtraction operators.Example:->>

Infix expression: $3 * \log( 10 )$

Postfix expression:

$=3 * (10 \log)$ //(Priority of unary operatorlogforces $\log( 10 )$ to evaluate first.)

$=3 \ 10 \log *$

Now for our case $3*\log(x + 1) - a / 2$

First content inside parenthesis will be evaluated

So, $x+1$ will become $x\;1+$

Now among $(*,/,\log,+,-)$ operators, $\log$ has highest priority as it is the only unary operator

So, $\log(x\;1+)$ will become ${x\;1+\log}$

Now suppose** ** ${z= x1+\log}$ and we get $3* z - a / 2$

$\implies 3z* a\;2/ -$

Now, substitute $z= x\;1+\log$ and we get

$\mathbf{3x\;1+\log* a\;2/ -}$ as answer.

+13 votes

+10 votes

**We can do directly(manually) =>**

**3*log(x + 1) - a / 2**

**= ((3*(log(x + 1))) - (a / 2))**

**= ((3*log(x1+))) - (a2/))**

**= ((3*x1+log) - (a2/))**

**= ((3x1+log*) - (a2/))**

**= 3x1+log*a2/-**

+9 votes

Given infix expression : $3*log(x+1)- \frac{a}{2}$

Expression tree :

Do a postorder traversal of the above tree to get postfix expression: $3x1+log*a2/-$

+1 vote

Why to go for long description, draw tree and enjoy what you want prefix, infix postfix or even converse pre, in and post.

Once go from my ans.

0 votes

we know that in infix expression, operator that is being evaluated at last is root.

Therefore, 3∗log(x+1)−a/2 infix expression can be shown in tree as-

- is evaluated at last here, so we can write it at first in tree, hence the root.

Similarly for other operators like

(x+1) is evaluated at very first therefore we can write it at last in the below tree.

Now traverse it in postfix fashion like **Left Right Root, **we can get the following postfix expression as:

**3x1+log∗a2/−**

52,315 questions

60,426 answers

201,748 comments

95,226 users