Question
Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is _____.
Official answer and solution
- Official answer
- 6
- From
- Official GATE 2014 answer key
Solution
Expand the algebraic expression defined by the binary expression tree and set binary leaf values to maximize the result.
-
Tree Expression Decomposition:
Let the eight leaves from left to right be denoted .-
Left Subtree:
- Left child is
+with leaves . - Right child is
−with leaves . - Root of left subtree is
−:
- Left child is
-
Right Subtree:
- Left child is
−with leaves . - Right child is
+with leaves . - Root of right subtree is
+:
- Left child is
-
-
Overall Root Expression:
The root operator is+: -
Maximizing the Expression:
- The coefficients of the 8 variables are:
- There are 6 variables with coefficient () and 2 variables with coefficient ().
- To maximize , assign value to every variable with coefficient , and assign value to every variable with coefficient :
- The coefficients of the 8 variables are:
6
Misinterpreting the minus operator signs when removing parentheses in nested subtrees.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 2
- Question
- 49 of 65, printed as CS Q.39
- 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.