in DS retagged by
15,639 views
43 votes
43 votes
Compute the post fix equivalent of the following expression $3^*\log(x+1)-\frac{a}{2}$
in DS retagged by
by
15.6k views

4 Comments

so unary opern of  log(x1+) == x1+log ??

2
2
yes u can say
1
1
just construct expression tree and do post order traversal.....no need to worry about priorities
3
3

9 Answers

94 votes
94 votes
Best answer
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

2 Comments

thanx a lot
3
3
But in C lang, there is no exponentiation operator!
0
0
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 / -$

4 Comments

i m not getting it ..... can you please explain me ...

 

by the expanding it .... fully
0
0
brother how to write the postfix of these two??
1. a++ ,  do i have to expand like a=a+1 and then proceed?  Please explain in detail.
2 ++a + b++
0
0

i think the first one i,e a++ is already a postfix expression.

and the 2nd one  i.e ++a+b++  can be written as   a++b+++ .

pls verify once!

0
0
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/-$

4 Comments

How to make the expression tree just by looking at the Infix expression.
0
0
this expression tree is wrong correct expression tree should be:
 expression tree just do postorder evaluation of this to get the amswer.    
            -
          /    \
         *      /
        /  \    /  \
       3   log a  2
            /   \
                +
                /  \
               x    1
0
0

@Radha mohan

how you are so sure the x+1 is on the right child of log in expression tree.

0
0

but it doesn’t matter in postorder traversal.

0
0

Related questions