Prefix and postfix notations are also known as Polish notation and reverse Polish notation, in honor of the inventor's nationality. These notations are used as the syntax of mathematical expressions in programming languages because they do not need parenthesis therefore are easier and quicker to interpret.
Steps to convert an infix notation into prefix or postfix:
1. Fully parenthesize the infix expression. For example (2x + y) / (x-2y) becomes
( ( ( 2* x) +y) / (x - (2*y) ) )
2. List all operands in the order of appearance:
2 x y x 2 y
3. Review and note down the order of precedence in the infix expression in step 1: *, +, *, -, /
4. Follow the order in step 3, insert the operators before or after corresponding operands in step 2:
prefix: *2 x y x 2 y -> +*2 x y x 2 y -> +*2 x y -x *2 y -> /+*2 x y -x *2 y
postfix: 2 x* y x 2 y -> 2 x* y+ x 2 y -> 2 x* y+ x 2 y* - -> 2 x* y+ x 2 y*-/
More examples in the videos on this page:
http://www.categories.acsl.org/wiki/index.php?title=Prefix/Infix/Postfix_Notation
We went through DraftPick in the class. Here is the link to the solution of ACSL_Search in case you are curious. We will go through this example this coming weekend.
Your Challenges:
Prefix/Postfix short questions: 1) #1 and #2 in 2014-15C2jr. 2) #1 and #2 in 2015-16C2jr.pdf
Coding task: ACSL_Lisp_jr
2014-2015
1. 3
2.i didn't get how to do it:(
2015-2016
1.108????
2.I have no idea about this one.
2014-2015
1)3
2)3x2^*4y*+xy2^2*-4x*5y*/+
2015
1)108
2)b a b c - 2^*/ c a 2^/-
2014-15
1. 3
2. 3 x 2^* 4 y*+ 2 x*- 2 y 2^*+ 4 x*+ 5 y*/
2015-16
1. 23
2. -/*a ^-b c 2 b /c ^a 2
2014-2015
1) three
2) 3 x^2 * 4 y * 2 - x y^2+ * 4 x +* 5 y * /
2015-2016
1) 352??
2) - ^2 b c * a / b - ^2 / a c
1)
1. 3
2. 3x2^*4y*2xy2^+*4x*5x*/+-+
2)
1. 108
2. abc-2^*b/ca2^/-
2014-2015 1.3 2.3x2^4y*-xy2^*2*4x*5y*/+ 2015-2016 1.108 2.-/*a^-bc2b/c^a2
up arrow: ! exponent: #
2016
1. 14/17!*+17*12-*12/-
2. a*(b - c)!2/b - c/(a!2)
2015
1. +-/*2 + 12!6/6 + 3
2. +-3 x#2 4 y 2 + x y#2 4 x 5 y+-