Knowee
Questions
Features
Study Tools

Convert Infix Expression into the Post fix Expression.          (3 + 5) * 2 / (2 ^ 3 - 1)

Question

Convert Infix Expression into the Postfix Expression

Convert the following infix expression into its equivalent postfix form:

(3 + 5) * 2 / (2 ^ 3 - 1)
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here are the steps to convert the infix expression (3 + 5) * 2 / (2 ^ 3 - 1) into postfix expression:

  1. First, we need to understand the precedence of operators. The precedence order is as follows: Parentheses, Exponents, Multiplication and Division (from left to right), Addition and Subtraction (from left to right).

  2. Start scanning the infix expression from left to right.

  3. If the scanned character is an operand, output it.

  4. Else,

    • If the precedence of the scanned operator is greater than the precedence of the operator in the stack(or the stack is empty), push it.
    • Else, Pop the operator from the stack until the precedence of the scanned operator is less-equal to the precedence of the operator residing on the top of the stack. Push the scanned operator to the stack.
  5. If the scanned character is an '(', push it to the stack.

  6. If the scanned character is an ')', pop and output from the stack until an '(' is encountered. Remove both '(' and ')'.

  7. Repeat steps 3-6 until infix expression is scanned.

  8. Pop and output from the stack until it is not empty.

Let's apply these steps to our expression (3 + 5) * 2 / (2 ^ 3 - 1):

  • Scan (3 + 5), according to the rule, push ( to the stack, output 3, push + to the stack, output 5, encounter ), pop and output + from the stack, remove ( and ). Now the output is 35+.

  • Scan * 2, push * to the stack (because * has higher precedence than +), output 2. Now the output is 35+2.

  • Scan / (2 ^ 3 - 1), push / to the stack (because / has the same precedence as *), push ( to the stack, output 2, push ^ to the stack (because ^ has higher precedence than /), output 3, encounter -, pop and output ^ from the stack (because ^ has higher precedence than -), push - to the stack, output 1, encounter ), pop and output - from the stack, remove ( and ). Now the output is 35+2*23^1-.

  • Pop and output from the stack until it is not empty, we get / *. Now the output is 35+2*23^1-/.

So, the postfix expression of (3 + 5) * 2 / (2 ^ 3 - 1) is 35+2*23^1-/.

This problem has been solved

Similar Questions

Convert Infix Expression into the Post fix Expression.          (3 + 5) * 2 / (2 ^ 3 - 1)

Select the expression(s) that result in a SyntaxErrorSyntaxError.8 / (3 / (2 / 3)))6 + -24 **5 * (3 + 2)

Add enough parentheses to the expression 3 + 4 / 2 - 7 3 + 4 / 2 - 7  so that the operations are evaluated in the following order: +, -, /.

Write the postfix expression for the following expression(A+B)*C-D*E/F (Don't leave space between the characters)

Predict the correct output for the given expression: 5|2 and 5^3 ?Options7 and 610 and 1257 and 225 and 15

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.