Question 12Asked in DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2

Assume two binary operators '^' and 'v'. '^' has higher precedence than 'v'. Operator '^' is right associative while operator 'v' is left associative. Which…

Assume two binary operators '^' and 'v'. '^' has higher precedence than 'v'. Operator '^' is right associative while operator 'v' is left associative. Which of the following represents the expression tree for the given expression? (9 v 3 ^ 4 v 2)
  1. ARoot v with left child ^ and right child 2; the ^ node has left child 9 and right child v, whose children are 3 and 4.
  2. BRoot v with left child v and right child 2; the inner v has left child 9 and right child ^, whose children are 3 and 4.
  3. CRoot v with left child v and right child 2; the inner v has left child ^ (children 3 and 4) and right child 9.
  4. DRoot v with left child 2 and right child v; the inner v has left child 9 and right child ^, whose children are 3 and 4.
Show answerHide answer

Correct answer: (B) Root v with left child v and right child 2; the inner v has left child 9 and right child ^, whose children are 3 and 4.

Explanation

^ binds tighter, so 3 ^ 4 is grouped first: 9 v (3 ^ 4) v 2. v is left associative, so it is (9 v (3 ^ 4)) v 2: root v with left child the inner v and right child 2.

From DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2

This is question 12 of DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.