Stack Questions

These questions are generally asked in university exam

infix, prefix based stack question


21. Convert the infix expression (A+B)*(C-D) to prefix expression.

Answer:

To convert the infix expression (A+B)*(C-D) to prefix expression, we need to follow the operator precedence and associativity rules.
The steps are as follows:
1. First, convert (A+B) and (C-D) to prefix.
2. (A+B) becomes +AB and (C-D) becomes -CD.
3. Now, multiply these two sub-expressions.
4. The final prefix expression is *+AB-CD.

22. Convert the prefix expression *+AB-CD to infix expression.

Answer:

The given prefix expression is *+AB-CD.
1. Start from the rightmost operator and process each one sequentially.
2. First, we identify * as the operator. So, the infix form would be (A+B)*(C-D).
3. Therefore, the infix expression is (A+B)*(C-D).

23. Convert the infix expression A*(B+C/D) to prefix expression.

Answer:

To convert the infix expression A*(B+C/D) to prefix, follow these steps:
1. First, deal with the sub-expression inside parentheses (B+C/D).
2. C/D becomes /CD, and then (B+C/D) becomes +B/CD.
3. Finally, multiply this sub-expression with A, which gives us *A+B/CD.

24. Convert the prefix expression -+ABC to infix expression.

Answer:

The given prefix expression is -+ABC.
1. Start from the leftmost operator and process each one sequentially.
2. First, apply +AB, which becomes (A+B).
3. Next, apply the operator -, which gives us (A+B)-C.
4. Therefore, the infix expression is (A+B)-C.

25. Convert the infix expression (X+Y)/(Z-W) to prefix expression.

Answer:

To convert the infix expression (X+Y)/(Z-W) to prefix, follow these steps:
1. First, convert (X+Y) and (Z-W) to prefix.
2. (X+Y) becomes +XY and (Z-W) becomes -ZW.
3. Now divide these two sub-expressions.
4. The final prefix expression is /+XY-ZW.

27. Convert the infix expression (P/Q)+(R-S) to prefix expression.

Answer:

To convert the infix expression (P/Q)+(R-S) to prefix, follow these steps:
1. First, convert (P/Q) and (R-S) to prefix.
2. (P/Q) becomes /PQ and (R-S) becomes -RS.
3. Now add these two sub-expressions.
4. The final prefix expression is +/PQ-RS.

28. Convert the prefix expression +*AB/CD to infix expression.

Answer:

The given prefix expression is +*AB/CD.
1. Start from the leftmost operator and process each one sequentially.
2. First, apply *AB, which becomes (A*B).
3. Then, apply /CD, which becomes (C/D).
4. Finally, apply +, giving the infix expression as ((A*B)+(C/D)).

29. Convert the infix expression A/(B*C+D) to prefix expression.

Answer:

To convert the infix expression A/(B*C+D) to prefix, follow these steps:
1. First, deal with the sub-expression inside parentheses (B*C+D).
2. B*C becomes *BC, and then (B*C+D) becomes +*BCD.
3. Finally, divide this sub-expression by A, which gives us /A+*BCD.

30. Convert the prefix expression -*AB/CD to infix expression.

Answer:

The given prefix expression is -*AB/CD.
1. Start from the leftmost operator and process each one sequentially.
2. First, apply *AB, which becomes (A*B).
3. Then, apply /CD, which becomes (C/D).
4. Finally, apply -, giving the infix expression as ((A*B)-(C/D)).

31. Convert the infix expression (X-Y)*(Z+W) to prefix expression.

Answer:

To convert the infix expression (X-Y)*(Z+W) to prefix, follow these steps:
1. First, convert (X-Y) and (Z+W) to prefix.
2. (X-Y) becomes -XY and (Z+W) becomes +ZW.
3. Now multiply these two sub-expressions.
4. The final prefix expression is *-XY+ZW.

32. Convert the prefix expression /-AB*CD to infix expression.

Answer:

The given prefix expression is /-AB*CD.
1. Start from the leftmost operator and process each one sequentially.
2. First, apply -AB, which becomes (A-B).
3. Then, apply *CD, which becomes (C*D).
4. Finally, apply /, giving the infix expression as ((A-B)/(C*D)).

33. Convert the infix expression A+B*C-D to prefix expression.

Answer:

To convert the infix expression A+B*C-D to prefix, follow these steps:
1. First, multiply B and C to get *BC.
2. Then, add A to *BC to get +A*BC.
3. Finally, subtract D from +A*BC, which gives -+A*BCD.

35. Convert the infix expression (M+N)*(P-Q)/R to prefix expression.

Answer:

To convert the infix expression (M+N)*(P-Q)/R to prefix, follow these steps:
1. First, convert (M+N) and (P-Q) to prefix.
2. (M+N) becomes +MN and (P-Q) becomes -PQ.
3. Multiply +MN and -PQ, which gives *+MN-PQ.
4. Finally, divide by R to get / *+MN-PQ R.