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

Expression tree with operators plus and minus and leaves with values 0 or 1
Binary expression tree with operators + and - and leaf inputs 0 or 1
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.

  1. Tree Expression Decomposition:
    Let the eight leaves from left to right be denoted x1,x2,x3,x4,x5,x6,x7,x8∈{0,1}x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8 \in \{0, 1\}.

    • Left Subtree:

      • Left child is + with leaves x1,x2  ⟹  (x1+x2)x_1, x_2 \implies (x_1 + x_2).
      • Right child is − with leaves x3,x4  ⟹  (x3−x4)x_3, x_4 \implies (x_3 - x_4).
      • Root of left subtree is −:
        L=(x1+x2)−(x3−x4)=x1+x2−x3+x4.L = (x_1 + x_2) - (x_3 - x_4) = x_1 + x_2 - x_3 + x_4.
    • Right Subtree:

      • Left child is − with leaves x5,x6  ⟹  (x5−x6)x_5, x_6 \implies (x_5 - x_6).
      • Right child is + with leaves x7,x8  ⟹  (x7+x8)x_7, x_8 \implies (x_7 + x_8).
      • Root of right subtree is +:
        R=(x5−x6)+(x7+x8)=x5−x6+x7+x8.R = (x_5 - x_6) + (x_7 + x_8) = x_5 - x_6 + x_7 + x_8.
  2. Overall Root Expression:
    The root operator is +:

    E=L+R=(x1+x2−x3+x4)+(x5−x6+x7+x8)E = L + R = (x_1 + x_2 - x_3 + x_4) + (x_5 - x_6 + x_7 + x_8)
    E=x1+x2−x3+x4+x5−x6+x7+x8.E = x_1 + x_2 - x_3 + x_4 + x_5 - x_6 + x_7 + x_8.
  3. Maximizing the Expression:

    • The coefficients of the 8 variables are:
      +1,+1,−1,+1,+1,−1,+1,+1.+1, +1, -1, +1, +1, -1, +1, +1.
    • There are 6 variables with coefficient +1+1 (x1,x2,x4,x5,x7,x8x_1, x_2, x_4, x_5, x_7, x_8) and 2 variables with coefficient −1-1 (x3,x6x_3, x_6).
    • To maximize EE, assign value 11 to every variable with coefficient +1+1, and assign value 00 to every variable with coefficient −1-1:
      Emax⁡=1+1−0+1+1−0+1+1=6.E_{\max} = 1 + 1 - 0 + 1 + 1 - 0 + 1 + 1 = 6.
Final answer

6

Common trap

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.