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:
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.
Coding task: ACSL_Lisp_jr