Search code examples
c++cequationinfix-notationpostfix-notation

Postfix to Infix conversation


I can not solve this expression from postfix to infix. Please help me to understand in detail

5 x y - / x y + 3 ^ 7 / +

Solution

  • postfix to infix:

    5 x y - / x y + 3 ^ 7 / +
    

    STEP

    5 x y - /
    A) 5xy-/ = 5 (x-y)/ = (5 / (x-y))
    x y +
    B) x y + = (x + y)
    (x+y) 3 ^
    B.1) (x + y) 3 ^ = ((x + y) ^ 3 )
    Now, (5 / (x-y)) ((x + y) ^ 3 ) 7 / +
    = (5 / (x-y)) (((x + y) ^ 3 )/7 ) + = (5 / (x-y)) + (((x + y) ^ 3 )/7 )

    POSTFIX and PREFIX are expression in which no brackets are used. Precedence of operator are decided in order of there appearance in expression, So to evaluate expression no need to search next operation to perform- FAST .

    While in INFIX expression precedence of operators are overwritten by brackets. hence brackets are there in infix expression- Need to search which operation to perform e.g. A+B%D - hence SLOW.
    That is the reason conversion are useful in computer science.