edited by
365 views

2 Answers

Best answer
2 votes
2 votes

Refer the link that Arjun Sir Provided in the Comment for Detailed explanation on similar Question.

I'll answer what you asked.

While Converting Infix to Postfix... We basically do the following  :

1. Print Operand as soon as you see it while scanning left to right.

2. Push Operators on the Operator stack (With added conditions....I assume you happen to know the Algorithm of Conversion from Infix to Postfix) Refer here for Algo if not : http://faculty.washington.edu/jstraub/dsa/aexp/

Our Expression is = $3*log(x+1)*\frac{a}{2}$

Scan from left to right :

We scan $3$.. Operand it is.. hence Print it in Postfix expression.  Hence our Postfix expression = $3$

Scan $*$..Binary Operator it is.. Push Onto Stack... Stack looks like this..

 
 
$*$

Scan $log$..Unary Operator it is..Hence It has more Priority than $*$, Hence we Push it on $*$ ..

 
$log$
$*$

Scan $($.. Push it... (Open Parentheses is always of more priority than outside operators)

$($
$log$
$*$

Scan $x$.. Operand it is.. Print it in our Postfix expression..Hence, Our Postfix expression = $3x$

Scan $+$.. Binary Operator... Since On top of the Stack $($ is there,(Open Parentheses is always of less priority than inside operators) Hence Push it. 

$+$
$($
$log$
$*$

Scan $1$.. Operand.. Print it.. Our Postfix expression = $3x1$

Scan $)$.. Close Parentheses.. Now Pop one by one(including $($) until $($ is encountered and Print them in our Postfix expression (Don't print $(,)$) ..Hence, Our Postfix expression = $3x1+$

 
$log$
$*$

Scan $*$.. Binary Operator... Less priority than $log$..(Unary operator has more priority than Binary )..Hence Pop $log$ and print. 

Our Postfix expression = $3x1+log$

Now, We have $*$ on top of stack, And Item being scanned is also $*$ Hence, Associativity comes into picture. Hence, Old $*$ more Priority. Pop it and print it. And Push $*$ being scanned.

Our Postfix expression = $3x1+log*$

Scan $a$.. Operand... Print. Our Postfix expression = $3x1+log*a$

Scan $/$.. Operator.. $*$ and $/$ same priority hence associativity kicks in. Hence Pop $*$ and Print and Push $/$

Our Postfix expression = $3x1+log*a*$

Scan $2$.. Opereand.. Print.. Our Postfix expression = $3x1+log*a*2$

Pop everything that is there in Stack...

 Our Postfix expression = $3x1+log*a*2/$

selected by

Related questions

0 votes
0 votes
2 answers
2
viral8702 asked Sep 21, 2023
275 views
The Total Combinations Possible of Min heap with 8 Distinct elements are ?
0 votes
0 votes
1 answer
3
iamdeepakji asked Jan 27, 2019
266 views
If there is negative edge cycle then dijkstra algorithm will give correct path or not same thing about bellman ford also?Bellman ford always halts or not?
0 votes
0 votes
1 answer
4
iamdeepakji asked Dec 27, 2018
385 views
Please solve this by taking some exampleBack edgecross edgetree edgeThankyou.