Question

In: Computer Science

1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b)...

1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b) A*B+C*Dc) X × Y + W × Z + V × U

2) Consider the postfix (reverse Polish notation) 10 5 + 6 3 - /. What is the equivalent infix expression?

Solutions

Expert Solution

1) What we mean by a postfix expression is that the expression is always of the form AB op where A and B are two operands whereas op is an operator such as +, -, *, /, ^, etc. In simple words, when an operator is written and follows after every pair of operands, it is known as a postfix expression. Keep in mind that even during the conversion from infix to postfix expressions, the order of operator precedence remains the same as is in the normal case.

1a) The equivalent postfix (reverse Polish notation) expression of 16/(5+3) is 16 5 3 + /

Explanation: Let’s convert the expression 16/(5+3) using operator precedence. 5 and 3 are added first because they are inside the parenthesis ( ) and we know that ( ) has the highest precedence out of all the operator. Hence, 5+3 will be written as 5 3+ which is a postfix expression as explained in the starting. Here we can see that 5 and 3 are the operands and + is the operator. After 5 and 3 are added, then 16 is divided by the addition result of 5 and 3. Now, here again, we will have 16 / (5 3 +), and finally, we will write it in the postfix expression form as 16 5 3 + /

Infix Expression

Postfix Expression

5+3

5 3+

16/5+3

16 5 3+ /

1b) The equivalent postfix (reverse Polish notation) expression of A*B+C*D is A B * C D * +

Explanation: Similar explanation goes for this problem also. Here we know that A will be multiplied with B and C will be multiplied with D and finally, the result of both the products will be added to each other. This is because we know that multiplication * has higher precedence than addition +

So,

1c) The equivalent postfix (reverse Polish notation) expression of X × Y + W × Z + V × U is X Y * W Z * + V U * +

Explanation: Similar explanation goes for this problem also. Here we know that X will be multiplied with Y and W will be multiplied with Z and then V will be multiplied with U. Finally, the result of all the three products will be added to each other. This is because we know that multiplication * has higher precedence than addition +

So,

-------------------------------------------------------------------------------------------------

2) The equivalent infix expression of the postfix (reverse Polish notation) 10 5 + 6 3 - / is (10+5) / (6-3)

Explanation: The exact opposite happens when we convert a postfix expression to an infix expression. Suppose the postfix expression is written as A B + it means that its equivalent infix expression will be A+B. Hence in an infix expression, the operator (here +) is always written between the two operands (here A and B). Always keep this trick in your mind that when converting from postfix to infix expression, start scanning from left to right in the postfix expression and keep on writing the equivalent infix expressions.

So,

Thanks!


Related Solutions

(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses....
(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses. For example, the expression ( 11 + 12 ) * 13 would be written as 11 12 + 13 * Assume that ALWAYS there is a space between operands and operators in the input expression. Use two stacks, one to store the operands and one to store the operators. Your program only accpets following operators : ( ) + - / * Write a...
java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expres
java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expression                                                 Stack                             Postfix Expression ---------------------------------------------------------------------------------------------------------------------------- 8 - 9*(2 + 1/4) + 3*7                                                     (empty)                            (blank) Evaluate the following Postfix expression. Once again, show all work.            Postfix                                               Stack                     Result           ---------------------------------------    --------------------    --------------            2 7 + 12 4 / * 8 5 + -
C++ Data Structure Write a program to change following infix expressions to postfix expressions using a...
C++ Data Structure Write a program to change following infix expressions to postfix expressions using a stack a) D-B+C b) C*D+A*B c) (A*B)*C+D*F-C d) (A-4*(B-C)-D/E)*F
Convert the expression into postfix notation 19 + 2 ∗ 5  + (1 - 6/(1 ∗ 2))
Convert the expression into postfix notation 19 + 2 ∗ 5  + (1 - 6/(1 ∗ 2))
2. Convert the following infix form expression into the postfix form expression by using a stack:...
2. Convert the following infix form expression into the postfix form expression by using a stack: A+(B*(C-D)+E)/F-G*H Show the stack after each push/pop.
Use stack to evaluate postfix expressions : 5 4 2 1 + 6 * + 3...
Use stack to evaluate postfix expressions : 5 4 2 1 + 6 * + 3 + *
The following postfix expression 2 6 + 3 5 - / evaluates to Group of answer...
The following postfix expression 2 6 + 3 5 - / evaluates to Group of answer choices -1 1 -4 4 this is not a postfix expression In an array implementation of the StackInterface where push() and pop() are O(1), the top of the stack is Group of answer choices the first entry in the array the last occupied entry in the array the second entry in the array the entry before the last ocuppied entry in the array the...
Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4...
Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4 – 9 b) ( 2 + 6 ) / ( 3 – 5 ) . Algorithm WRITE STEP BY STEP Scan the characters in the infix expression. While there are characters left in the infix expression: Check the next character in the expression. 1. If the next character is operand, remove it from the expression and push it onto the operand stack. 2. If...
For the following infix expression, build the corresponding expression tree. 1.1 a*b 1.2 a+b*c 1.3 a+b*c/d-e...
For the following infix expression, build the corresponding expression tree. 1.1 a*b 1.2 a+b*c 1.3 a+b*c/d-e Perform pre-order and post-order traversal of the above binary expression trees. What relationship exists among these scans and prefix and postfix notation for the expression?
Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C...
Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C * D) / S + F)             Where the values of the variables are:                         Z = 3, B = 6, C = 2, D = 5, S = 4 , F = 21             Evaluate the expression using a stack. Shows the logical representation of the evaluation process. ..............................................................................
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT