Data Structure Questions and Answers – Evaluation of an Infix Expression (Not Parenthesized)

«
»

This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Evaluation of an Infix Expression (Not Parenthesized)”.

1. 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.
advertisement

2. 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. 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.
advertisement
advertisement

4. 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. 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.
advertisement

6. 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. 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 ^.
advertisement

8. 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. 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.
advertisement

10. 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. 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. 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. 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.

Sanfoundry Global Education & Learning Series – Data Structure.

To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter