• edited by
19,758 views
42 42 votes

Assume that the operators $+, -, \times$ are left associative and $\;\hat{}\; $ is right associative. The order of precedence (from highest to lowest) is $ \ \;\hat{}\;, \times, +, -$. The postfix expression corresponding to the infix expression $a+ b \times c-d ^ \ \ \hat{}\ e^ \  \hat{} \ f$ is

  1. $abc\times+def \ \ \hat{}{} \ \ \ \hat{}-$

  2. $abc\times+de\ \ \hat{} \ \ f \ \ \hat{} \ \ -$

  3. $ab+c\times d-e \ \ \hat{} \ \ f \ \ \hat{}$

  4. $-+a\times bc \ \ \hat{} \ \ \ \hat{} \ \ def$

5 Answers

Best answer
73 73 votes

Answer is (A).

Here is the procedure first :
Scan Infix Expression from left to right whenever you see operand just print it.
But, in case of operator
if(stack is empty) then push it.
if(precedence(tos) $<$ precedence(current operator) ) push it. where, tos means top of stack.
else if (precedence(tos) $>$ precedence(current operator) ) pop and print.
else if (precedence(tos) $==$  precedence(current operator) ) then check for associativity.In case Operators are Left to right then pop and print it otherwise push the current operator (Right to Left Associativity)
And once you have scanned infix expression completely. Make sure pop all the element and print it in same order.

Here, the infix expression is $a+b \times c−d ^\hat{} e ^\hat{}f$
$a$ : print it
$+$ : push into the Operator Stack
$b$ : print it
$*$ : its having higher precedence than $+$ then push into Operator Stack
$c$ : print it
$'-'$ : $'-'$ is having less precedence than $'*'$ so pop from operator stack and print $'*'$.after this stack will be having $'+'$ on top.which is having same precedence as $'-'$ but both are left to right associative then just pop $+$ and print it. Now stack is empty. Push $'-'$ to it.
$d$ : print it
'$^\hat{}$' : top of the stack is having $'-'$.'$^\hat{}$' has higher precedence than $'-'$.so simply push '$^\hat{}$' into stack
$e$ : print it.
'$^\hat{}$' : Now top of the stack is '$^\hat{}$' and has same precedence so associativity will come to picture. Since '$^\hat{}$' is right associative as given in question. So '$^\hat{}$' will be pushed.
$f$ : print it.

Now, we have scanned entire infix expression.Now pop the stack until it becomes empty.This way you will get $abc\times+def \ \ \hat{}{} \ \ \ \hat{}-$.

• edited by
12 12 votes

Use Bracket according to precedance 

^  - Precedance from Right to Left and others left to right

((a + (b * c )) - (d ^ (e ^ f))) then solve it 

6 6 votes
Given infix expression: $a+b\times c-d^ \ \ \hat{}\ e^ \ \ \hat{} \ f$

$\implies a+b\times c-d^ \ \ \hat{}\ (e^ \ \ \hat{} \ f)$

$\implies a+b\times c-(d^ \ \ \hat{}\ e f ^\  \hat{})$

$\implies a+(b\times c)- d\ e f ^\ \ \hat{} ^ \ \ \hat{}$

$\implies (a+bc\times)\ –\ d\ e f ^\ \ \hat{} ^ \ \ \hat{}$

$\implies (abc\times+) \ –\ (d\ e f ^\ \ \hat{} ^ \ \ \hat{})$

$\implies abc\times+  d\ e f ^\ \ \hat{} ^ \ \ \hat{} -$

Option $(A)$ is correct.
1 1 vote
answer - A
Answer:
Position:
Show:

Related questions

40 40 votes
6 answers 6 answers
30.0k
30.0k views
Kathleen asked Sep 18, 2014
30,027 views
The following numbers are inserted into an empty binary search tree in the given order: $10, 1, 3, 5, 15, 12, 16$. What is the height of the binary search tree (the heigh...
4 4 votes
3 answers 3 answers
4.7k
4.7k views
go_editor asked Jun 14, 2016
4,711 views
The infix expression $A+(B-C)^*D$ is correctly represented in prefix notation as$A+B-C^*D$$+A^*-BCD$$ABC-D^*+$$A+BC-D^*$
32 32 votes
3 answers 3 answers
15.6k
15.6k views
gatecse asked Sep 21, 2014
15,590 views
Let $f(x)$ be the continuous probability density function of a random variable $x$, the probability that $a < x \leq b$, is :$f(b-a)$$f(b) - f(a)$$\int\limits_a^b f(x) dx...
52 52 votes
4 answers 4 answers
24.8k
24.8k views
Kathleen asked Sep 21, 2014
24,828 views
The following postfix expression with single digit operands is evaluated using a stack:$$8 \ 2 \ 3 \ \;\hat{}\; ∕ \ 2 \ 3 * + 5 \ 1 * -$$Note that $\;\hat{}\;$ is the ...