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...
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
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...
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. ..............................................................................
Consider the following vectors: →a = 5 −1 3 3 →b = 5 0 1 0...
Consider the following vectors: →a = 5 −1 3 3 →b = 5 0 1 0 →c = −10 3 −3 −7 For each of the following vectors, determine whether it is in span{→a, →b, →c}. If so, express it as a linear combination using a, b, and c as the names of the vectors above. →v1 = 5 −3 2 7 < Select an answer > →v2 = 2 7 6 −7 < Select an answer > →v3 =...
What is the delta notation of a fatty acid with the omega notation 20:5 (w-3)?
What is the delta notation of a fatty acid with the omega notation 20:5 (w-3)?
Question 1) Given the byte value: 0xad a) What is the equivalent decimal notation as an...
Question 1) Given the byte value: 0xad a) What is the equivalent decimal notation as an unsigned value? b_ What is the equivalent decimal notation as a signed value? Question 2) Below are integer values and the location where each is stored, which may be an address in memory or a register: Value    Location 0xc       0x130 0x82     0x134 0x5       %rdi 0x134    %rsi What are the values of the following operands? You may answer in decimal or hexadecimal, but if you...
x is 5, what is the result of the following Boolean expressions: 1. x != 0  ...
x is 5, what is the result of the following Boolean expressions: 1. x != 0   2. x > 0   3. x != 0 4. x > 0 5. (x >= 0) || (x < 0) 6. (x != 1) == !(x == 1) 7. (true) && (3 > 4) True or False? Please explain how you got your answers. I've been struggling with Boolean expressions so I'd like a little bit more of an explanation as to why each...
Please explain why B is the correct answer, I know on the 5'---->3' it goes reverse...
Please explain why B is the correct answer, I know on the 5'---->3' it goes reverse and 3'-->5' it goes forward.......I got lost after this. Please explain. Will give a thumbs up. ----- Which of the following sets of primers could you use to amplify the target DNA sequence below, which is part of the last protein-coding exon of the gene involved in cystic fibrosis? 5’- ggctaagatctgaattttccgag … ttgggcaataatgtagcgcctt - 3’ 3’- ccgattctagacttaaaaggctc … aacccgttattacatcgcggaa – 5’ a) 5’ GGAAAATTCAGATCTTAG...
Consider two assets, A and B. A earns +4%, –5%, or +3%, in scenarios 1, 2,...
Consider two assets, A and B. A earns +4%, –5%, or +3%, in scenarios 1, 2, and 3. B earns –5%, +3%, or +4%, in scenarios 1, 2, and 3. Compute the expected rates of return and SD for each asset, A and B. Now, consider a portfolio of assets A and B called AB, where the investor holds fraction 62% of his portfolio in A and fraction (1-62%) in B. Compute the standard deviation of AB and report this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT