What is the significance of reverse polish notation?

Question Detail: 

I teach computing to 18 year olds. After having reverse polish notation explained to them one asked why is it significant enough to be in the public exam. I explained the historical significance of 70s calculators but this failed to really address the issue. So are there and concurrent practical or theorhetical applications of RPN.

Asked By : Matt Scott
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/4666

Answered By : Ravindra Bagale

In computer reverse polish notation is often used in stack-based and concatenative programming languages. It is also common in dataflow and pipeline-based systems, including Unix pipelines.
computer uses stack for evaluate the arithmetic expressions
suppose following expression
3+4
in computer stack, it pushesh the element in following order

 3  4  +  

i.e. top pointer points to + symbol

  +   //top pointer points here   4   3 


when computer starts to evaluate, it first pop the operator +, here computer checks, whether it is operator or any other characters, if it is operator then understand that it has to do addition operation, then it pop the two operands for arithmetic addition, i.e. these are the next elements of the stack. that is 4 & 3
here pop order is + 4 3
in short for solving complex expressions reverse polish notation is used

If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 − 4 + 5" in conventional infix notation would be written "3 4 − 5 +"in RPN: first subtract 4 from 3, then add 5 to that.

An advantage of RPN is that it obviates the need for parentheses that are required by infix. While "3 − 4 * 5"` can also be written "3 − (4 * 5)", that means something quite different from "(3 − 4) * 5". In postfix, the former could be written "3 4 5 * −", which unambiguously means "3 (4 5 *) −" which reduces to "3 20 −"; the latter could be written "3 4 - 5 *" (or 5 3 4 - *, if you wish to keep similar formatting), which unambiguously means "(3 4 -) 5 *".

No comments

Powered by Blogger.