prefix of (a+b)*(c-d) is
Answers
Answered by
2
Answer:
Prefix of (a+b)*(c-d) is * + ab - cd
Explanation:
- The 'Pre' refers to the relative position of the operator with respect to the two operands.
- In prefix notation the operator precedes the two operands.
- conversion of (a+b)*(c-d) to its prefix notation is as follows:
Step 1 : (+ab)*(-cd)
Step 2 : *(+ab)(-cd)
The prefix form of an expression requires no parenthesis.
Hence *(+ab)(-cd) should be written as * + ab - cd
Answered by
0
Answer:
Prefix expression is given by
Explanation:
Given: An infix expression
Find: Conversion from infix to prefix expression
Step1:
Infix :
- An expression is called the Infix expression if the operator appears in between the operands in the expression.
- Simply of the form (operand1 operator operand2).
- Example :
Prefix:
- An expression is called the prefix expression if the operator appears in the expression before the operands.
- Simply of the form (operator operand1 operand2).e.g.
Conversion step for infix to prefix expression
- To convert Infix to Prefix expression, computers usually use the stack data structure.
- Reverse the infix expression.
- Obtain the “nearly” postfix expression of the modified expression.
- Reverse the postfix expression.
- Push “)” onto STACK, and add “(“ to the end of the A
- Scan A from right to left and repeat steps 3 to 6 for each element of A until the STACK is empty
- If an operand is encountered add it to B
- If a right parenthesis is encountered push it onto STACK
- If an operator is encountered then:
- a. Repeatedly pop from STACK and add to B each operator (on the top of STACK) which has the same or higher precedence than the operator.
- b. Add operator to STACK
- If left parenthesis is encountered then
- a. Repeatedly pop from the STACK and add to B (each operator on top of stack until a left parenthesis is encountered)
- b. Remove the left parenthesis
- Exit
Similar questions