retagged by
15,576 views
44 votes
44 votes
Compute the post fix equivalent of the following expression $3^*\log(x+1)-\frac{a}{2}$
retagged by

9 Answers

Best answer
95 votes
95 votes
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 as sin  is 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 operator log forces $\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.

edited by
15 votes
15 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/- 

13 votes
13 votes
$3 x 1 + \log * a 2 / -$
11 votes
11 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/-$

Related questions

4 votes
4 votes
1 answer
1
makhdoom ghaya asked Nov 29, 2016
1,876 views
Compute the postfix equivalent of the following infix arithmetic expression$a + b \ast c + d * e \uparrow f$where $\uparrow$ represents exponentiation. Assume normal ope...
28 votes
28 votes
3 answers
2
Kathleen asked Sep 29, 2014
8,538 views
Which of the following is essential for converting an infix expression to the postfix form efficiently?An operator stackAn operand stackAn operand stack and an operator s...
33 votes
33 votes
4 answers
3
32 votes
32 votes
5 answers
4
Kathleen asked Sep 18, 2014
12,744 views
Assume that the operators $+, -, \times$ are left associative and $^\hat{}$ is right associative. The order of precedence (from highest to lowest) is $ \ ^\hat{}, \times,...