Question
Official answer and solution
- Official answer
- A
- From
- Official GATE 2018 answer key
Solution
Deduce operator precedence from tree depth and operator associativity from branch direction.
In a parse tree for an arithmetic expression:
- Precedence: Operators evaluated deeper in the tree have higher precedence because their results are computed first and passed upward. In the given tree, the subexpression containing
$operations () is nested inside the#operations. Therefore, operator$has higher precedence than#.
- Associativity:
- For
$: The subtree evaluating is structured as , which grows to the left. Hence,$is left associative. - For
#: The expression evaluates , with#grouping to the right as . Hence,#is right associative.
Thus, $ has higher precedence and is left associative; # is right associative, matching option A.
Final answer
A
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2018 Computer Science and Information Technology (CS)
- Question
- 48 of 65, printed as CS Q.38
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.