Courses
Courses for Kids
Free study material
Offline Centres
More
Store Icon
Store
seo-qna
SearchIcon
banner

Which of the following is an example for a postfix expression?
A) $a*b(c + d)$
B) $abc* + de$
C) $ + ab$
D) $a + b - c$

Answer
VerifiedVerified
463.8k+ views
Hint: An arithmetic expression can be written in three ways:
Infix: $a*b$ : where the operator is between the two operands.
Prefix: $*ab$ : where the operator is preceding the two operands.
Postfix: $ab*$ : where the operator is post or after the two operands.
These are Polish representations.
Using this knowledge, we examine every option and try to find out if it’s a postfix expression or not.

Complete step by step solution:
We know that there are three types of expressions: Infix, Prefix and Postfix.
Let’s start by examining every option.
Option A: $a*b(c + d)$
This operation is a normal infix expression as the operator is in between the two operands on which the operation has to be performed.
Option B: $abc* + de$
This expression is neither prefix nor postfix.
We need to remember that a postfix expression will always have an operator at the end because the operator comes after the operands and also that a prefix expression will always have an operator at the beginning because the operator comes before the operands.
This is not an infix expression as well because two operators never come consecutively in an infix expression.
Option C: $ + ab$
This is clearly a prefix expression since the $ + $ operator is between the two operands.
Option D: $a + b - c$
This is clearly an infix expression since the operators are between their corresponding operands.
None of the options are postfix.

Note: Having a good idea about the definitions of postfix, prefix and infix expressions will help to solve the question. These expressions are Polish representations which make the work easier when evaluating an expression since there is not requirement of priorities or precedence of the operators. The equation can simply be evaluated by going from either left to right or right to left.


WhatsApp Banner