These questions are generally asked in university exam
convert infix to prefix based stack question
36. Convert the infix expression (A+B)*C-D to its prefix expression.
Answer: To convert the infix expression
(A+B)*C-D to prefix notation, follow these steps:
1. First, convert the innermost expression (A+B) to prefix,
which becomes +AB.
2. Next, apply the * operator to +AB and C, resulting in
*+ABC.
3. Finally, apply the - operator to *+ABC and D, resulting
in - *+ABC D. So, the prefix expression is - *+ABC D.
37. Convert the prefix expression *+AB-CD to its infix expression.
Answer: To convert the prefix expression
*+AB-CD to infix notation, follow these steps:
1. Start with the prefix expression *+AB-CD. The first operator
is *, so split the expression into * and the remaining part
+AB-CD.
2. Convert +AB to infix, which results in (A+B).
3. Convert -CD to infix, which results in (C-D).
4. Combine the results with *, resulting in (A+B)* (C-D). So,
the infix expression is (A+B)*(C-D).
38. Convert the infix expression A*(B+C)/D to its prefix
expression.
Answer: To convert the infix expression
A*(B+C)/D to prefix notation, follow these steps:
1. First, convert the inner expression (B+C) to prefix, which is
+BC.
2. Apply the * operator to A and +BC, resulting in *A+BC.
3. Finally, apply the / operator to *A+BC and D, resulting in /
*A+BC D. So, the prefix expression is / *A+BC D.
39. Convert the prefix expression /+A*BCD to its infix expression.
Answer: To convert the prefix expression
/+A*BCD to infix notation, follow these steps:
1. Start with the prefix expression /+A*BCD. The first operator
is /, so split the expression into / and +A*BCD.
2. Convert +A*BCD to infix: - The first operator in +A*BCD is +,
so split into + and A*BCD. - Convert *BCD to infix, which is
(B*C). - Combine with +, resulting in (A+(B*C)).
3. Combine with /, resulting in ((A+(B*C))/D). So, the infix
expression is ((A+(B*C))/D).
40. Convert the infix expression (A-B)/(C+D) to its prefix expression.
Answer: To convert the infix expression
(A-B)/(C+D) to prefix notation, follow these steps:
1. First, convert the inner expressions (A-B) and (C+D) to
prefix: - (A-B) becomes -AB. - (C+D) becomes +CD.
2. Apply the / operator to -AB and +CD, resulting in / -AB +CD.
So, the prefix expression is / -AB +CD.
42. Convert the infix expression A+B-C*D to its prefix expression.
Answer: To convert the infix expression A+B-C*D
to prefix notation, follow these steps:
- First, identify the highest precedence operation, which is multiplication. Thus, C * D becomes * C D.
- Next, substitute * C D back into the expression, resulting in A + B - * C D. This can be viewed as (A + B) - (* C D).
- Now, handle the addition: A + B becomes + A B, giving us - (+ A B) (* C D).
- Finally, combine everything to form the prefix expression: - + A B * C D.
43. Convert the prefix expression *+AB-CDE to its infix expression.
Answer: To convert the prefix expression
*+AB-CDE to infix notation, follow these steps:
1. Start with the prefix expression *+AB-CDE. The first operator
is *, so split the expression into * and +AB-CDE.
2. Convert +AB to infix, which is (A+B).
3. Convert -CDE to infix: - The first operator in -CDE is -, so
split into - and CDE. - Convert CDE to infix, which is (C-D). -
Combine with -, resulting in (C-D).
4. Combine with *, resulting in ((A+B)*(C-D)). So, the infix
expression is ((A+B)*(C-D)).
44. Convert the infix expression (A+B)*(C-D) to its prefix expression.
Answer: To convert the infix expression
(A+B)*(C-D) to prefix notation, follow these steps:
1. Convert the inner expressions (A+B) and (C-D) to prefix: -
(A+B) becomes +AB. - (C-D) becomes -CD.
2. Apply the * operator to +AB and -CD, resulting in *+AB -CD.
So, the prefix expression is *+AB -CD.
45. Convert the prefix expression *-A/BCD to its infix expression.
Answer: ((A−(B/C))∗D) To convert the prefix
expression *-A/BCD to infix notation, follow these steps:
1. Start from the rightmost side and find the operators and
operands:
2. Identify the operands first and group them with operators as
per the operator precedence.
3. Start applying operators from left to right:
- First, /BC becomes (B / C)
- Next, -A/BC becomes (A - (B / C))
- Finally, *(A - (B / C))D becomes ((A - (B / C)) * D)
46. Convert the infix expression A/(B+C-D) to its prefix expression.
Answer: To convert the infix expression
A/(B+C-D) to prefix notation, follow these steps:
1. Convert the inner expression (B+C-D) to prefix: - First,
convert B+C to prefix, which is +BC. - Next, convert +BC-D to
prefix, which is -+BCD.
2. Apply the / operator to A and -+BCD, resulting in /A-+BCD.
So, the prefix expression is /A-+BCD.
47. Convert the prefix expression +A/B*CD to its infix expression.
Answer: To convert the prefix expression
+A/B*CD to infix notation, follow these steps:
1.Start from the rightmost operator and go to the left.
2.Apply operators to operands following prefix notation
rules.
- * C D becomes (C * D)
- / B (C * D) becomes (B / (C * D))
- + A (B / (C * D)) becomes A + (B / (C * D))
48. Convert the infix expression (A-(B/C))*D+E to its prefix expression.
Answer: To convert the infix expression
(A-(B/C))*D+E to prefix notation, follow these steps:
1. Convert the inner expression (B/C) to prefix, which is /BC.
2. Apply the - operator to A and /BC, resulting in -A/BC.
3. Apply the * operator to -A/BC and D, resulting in *-A/BCD.
4. Finally, apply the + operator to *-A/BCD and E, resulting in
+*-A/BCDE. So, the prefix expression is +*-A/BCDE.
49. Evaluate following postfix expression using stack
ab*cd*+ , where a=2, b=2, c=3, d=4
