This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Evaluation of a Postfix Expression”.
1. Which of these operators have the highest order of precedence?
A) ‘(‘ and ‘)’
B) ‘*’ and ‘/’
C) ‘~’ and ‘^’
D) ‘+’ and ‘-‘
Explanation: The highest order of precedence is ~ and ^ followed by ‘*’ ,’ /’, ‘+’ ,’-‘ and then braces ‘(‘ ‘)’.
2. Which of the following is not an application of stack?
A) evaluation of postfix expression
B) conversion of infix to postfix expression
C) balancing symbols
D) line at ticket counter
Explanation: Conversion of infix to postfix language, balancing symbols, and line at ticket counter are all queue applications, while conversion of infix to postfix expression, balancing symbols, and line at ticket counter are all stack applications.
3. While evaluating a postfix expression, when an operator is encountered, what is the correct operation to be performed?
A) push it directly on to the stack
B) pop 2 operands, evaluate them and push the result on to the stack
C) pop the entire stack
D) ignore the operator
Explanation: The first two operands are popped from the stack, evaluated, and the result is put back into the stack when an operator is encountered.
4. Which of the following statement is incorrect?
A) Postfix operators use value to their right
B) Postfix operators use value to their left
C) Prefix operators use value to their right
D) In postfix expression, operands are followed by operators
Explanation: Both prefix operators use right-to-left values, and all postfix operators use left-to-right values.
5. What is the result of the given postfix expression? abc*+ where a=1, b=2, c=3.
Explanation: The infix expression is a+b*c. Evaluating it, we get 1+2*3=7.
6. What is the result of the following postfix expression?
ab*cd*+ where a=2,b=2,c=3,d=4.
Explanation: The infix expression is a*b+c*d. Evaluating it, we get, 2*2+3*4=16.
7. Consider the stack
| 5 |
| 4 |
| 3 |
| 2 |.
At this point, ‘*’ is encountered. What has to be done?
A) 5*4=20 is pushed into the stack
B) * is pushed into the stack
C) 2*3=6 is pushed into the stack
D) * is ignored
Explanation: The first two operands of the stack are popped, evaluated, and the result is moved into the stack when an operator is encountered.
8. Evaluate the postfix expression ab + cd/- where a=5, b=4, c=9, d=3.
Explanation: The infix expression is (a+b)-c/d. Evaluating it, (5+4)-9/3 gives 6.
9. Evaluate and write the result for the following postfix expression
abc*+de*f+g*+ where a=1, b=2, c=3, d=4, e=5, f=6, g=2.
Explanation: The infix expression is a+b*c+(d*e+f)*g. Evaluating it, 1+2*3+(4*5+6)*2 gives 59.
10. For the given expression tree, write the correct postfix expression.
Explanation: The infix expression a+bc is obtained by evaluating the given expression tree. We get abc+ when we convert it to postfix.
11. What is the other name for a postfix expression?
A) Normal polish Notation
B) Reverse polish Notation
C) Warsaw notation
D) Infix notation
Explanation: A postfix expression is known as reverse polish Notation, while a prefix expression is known as Polish Notation or Warsaw Notation.
12. Which of the following is an example for a postfix expression?
Explanation: A postfix expression is abc*de-+. Others are infix expressions, while +ab is a prefix expression.
13. Reverse Polish Notation is the reverse of a Polish Notation.
Explanation: The opposite of polish notation is reverse polish notation. Despite the fact that both NPN and RPN read the expression from left to right, their methods are somewhat different.
14. What is the time complexity of evaluation of postfix expression algorithm?
A) O (N)
B) O (N log N)
C) O (N2)
D) O (M log N)
Explanation: The evaluation of infix, prefix, and postfix expressions has an O time complexity (N).
15. In Postfix expressions, the operators come after the operands.
Explanation: Operators come after operands in postfix expressions. The operands come after the operators in prefix expressions.
The evaluation time complexity of infix, prefix, and postfix expressions is O (N)…. Reason for this: Operators come after operands in postfix expressions. The operands come after the operators in prefix expressions. The Stack data structure can be used to test a postfix expression. The measures below can be used to test a postfix expression using the Stack data structure… Move the reading symbol to the Stack if it is operand. You must substitute a number for each variable and perform the arithmetic operations to test an algebraic expression. Since 6 + 6 = 12, the variable x is equal to 6 in the example above.