Related Articles

Related Articles

Data Structures | Tree Traversals | Question 6
  • Difficulty Level : Medium
  • Last Updated : 08 Feb, 2013

Consider two binary operators ‘\uparrow ‘ and ‘\downarrow‘ with the precedence of operator \downarrow being lower than that of the \uparrow operator. Operator \uparrow is right associative while operator \downarrow is left associative. Which one of the following represents the parse tree for expression (7 \downarrow 3 ­\uparrow 4 ­\uparrow 3 \downarrow 2)? (GATE CS 2011)

(A) A
(B) B
(C) C
(D) D

Answer: (B)

Explanation: Let us consider the given expression (7 \downarrow 3 \uparrow 4 \uparrow 3 \downarrow 2).

Since the precedence of \uparrow is higher, the sub-expression (3 \uparrow 4 \uparrow 3) will be evaluated first. In this sub-expression, 4 \uparrow 3 would be evaluated first because \uparrow is right to left associative. So the expression is evaluated as ((7 \downarrow (3 \uparrow (4 \uparrow 3))) \downarrow 2). Also, note that among the two \downarrow operators, first one is evaluated before the second one because the associativity of \downarrow is left to right.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :