0 votes
in Data Structures & Algorithms I by (110k points)
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

This interesting question is from Evaluation of an Infix Expression (Not Parenthesized) in portion Application of Stacks of Data Structures & Algorithms I

This question was addressed to me during an interview.

1 Answer

0 votes
by (110k points)
selected by
Best answer
correct choice is (a) 6

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

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.