Engineering Questions with Answers - Multiple Choice Questions

Data Structure MCQ – Evaluation of an Infix Expression (Not Parenthesized)

1 - Question

How many stacks are required for applying evaluation of infix expression algorithm?
a) one
b) two
c) three
d) four

View Answer

Answer: b
Explanation: Two stacks are required for evaluation of infix expression – one for operands and one for operators.




2 - Question

How many passes does the evaluation of infix expression algorithm makes through the input?
a) One
b) Two
c) Three
d) Four

View Answer

Answer: a
Explanation: Evaluation of infix expression algorithm is linear and makes only one pass through the input.




3 - Question

Identify the infix expression from the list of options given below.
a) a/b+(c-d)
b) abc*+d+ab+cd+*ce-f-
c) ab-c-
d) +ab

View Answer

Answer: a
Explanation: a/b+(c-d) is an infix expression since the operators are placed in between the operands.




4 - Question

Which of the following statement is incorrect with respect to evaluation of infix expression algorithm?
a) Operand is pushed on to the stack
b) If the precedence of operator is higher, pop two operands and evaluate
c) If the precedence of operator is lower, pop two operands and evaluate
d) The result is pushed on to the operand stack

View Answer

Answer: b
Explanation: If the precedence of the operator is higher than the stack operator, then it is pushed on to the stack operator.




5 - Question

Evaluate the following statement using infix evaluation algorithm and choose the correct answer. 1+2*3-2
a) 3
b) 6
c) 5
d) 4

View Answer

Answer: c
Explanation: According to precedence of operators, * is evaluated first. + and – have equal priorities. Hence, 1+6-2= 5.




6 - Question

Evaluation of infix expression is done based on precedence of operators.
a) True
b) False

View Answer

Answer: a
Explanation: During evaluation of infix expression, the operators with higher precedence are evaluated first, followed by operators with lower precedence.




7 - Question

Of the following choices, which operator has the lowest precedence?
a) ^
b) +
c) /
d) #

View Answer

Answer: d
Explanation: The operator with the lowest precedence is #, preceded by +, / and then ^.




8 - Question

The system throws an error if parentheses are encountered in an infix expression evaluation algorithm.
a) True
b) False

View Answer

Answer: b
Explanation: The algorithm holds good for infix expression with parentheses. The system does not throw error.




9 - Question

Evaluate the following and choose the correct answer.
a/b+c*d where a=4, b=2, c=2, d=1.
a) 1
b) 4
c) 5
d) 2

View Answer

Answer: b
Explanation: * and / have higher priority. Hence, they are evaluated first. Then, + is evaluated. Hence, 2+2=4.




10 - Question

Evaluate the following statement using infix evaluation algorithm and choose the correct answer. 4*2+3-5/5
a) 10
b) 11
c) 16
d) 12

View Answer

Answer: a
Explanation: 4*2 and 5/5 are evaluated first and then, 8+3-1 is evaluated and the result is obtained as 10.




11 - Question

Using the evaluation of infix expression, evaluate a^b+c and choose the correct answer. (a=2, b=2, c=2)
a) 12
b) 8
c) 10
d) 6

View Answer

Answer: d
Explanation: ^ has the highest precedence. Hence, 2^2 is evaluated and then 4+2 gives 6.




12 - Question

Evaluate the following infix expression using algorithm and choose the correct answer. a+b*c-d/e^f where a=1, b=2, c=3, d=4, e=2, f=2.
a) 6
b) 8
c) 9
d) 7

View Answer

Answer: a
Explanation: ^ has the highest order of precedence. Hence, 2^2 is evaluated first, and then, 2*3 and 4/4 are evaluated. Therefore, 1+6-1=6.




13 - Question

From the given expression tree, identify the infix expression, evaluate it and choose the correct result.
data-structures-questions-answers-evaluation-infix-expression-not-parenthesized-q13
a) 5
b) 10
c) 12
d) 16

View Answer

Answer: c
Explanation: From the given expression tree, the result of the infix expression is evaluated to be 12.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners