GateAI
Trees

GATE CSE 2014 Set 2 · Q39

NAT2 marksMedium

Time

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

GATE CSE 2014 Set 2 Q39 diagram

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 6

Trees

Let the leaves from left to right be denoted by x1,x2,x3,x4,x5,x6,x7,x8x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8, where each xi∈{0,1}x_i \in \{0, 1\}.

We evaluate the subtrees from the bottom up:

  1. Left subtree of the root:

    • Left child of (−)(-): x1+x2x_1 + x_2

    • Right child of (−)(-): x3−x4x_3 - x_4

    • Left subtree expression: (x1+x2)−(x3−x4)=x1+x2−x3+x4(x_1 + x_2) - (x_3 - x_4) = x_1 + x_2 - x_3 + x_4

  2. Right subtree of the root:

    • Left child of (+)(+): x5−x6x_5 - x_6

    • Right child of (+)(+): x7+x8x_7 + x_8

    • Right subtree expression: (x5−x6)+(x7+x8)=x5−x6+x7+x8(x_5 - x_6) + (x_7 + x_8) = x_5 - x_6 + x_7 + x_8

  3. Root operation (+)(+):

    Total Expression=(x1+x2−x3+x4)+(x5−x6+x7+x8)\text{Total Expression} = (x_1 + x_2 - x_3 + x_4) + (x_5 - x_6 + x_7 + x_8)
    Total Expression=x1+x2−x3+x4+x5−x6+x7+x8\text{Total Expression} = x_1 + x_2 - x_3 + x_4 + x_5 - x_6 + x_7 + x_8

To maximize this expression, we set all positively signed terms to 11 and all negatively signed terms to 00:

  • x1=1,x2=1,x4=1,x5=1,x7=1,x8=1x_1 = 1, x_2 = 1, x_4 = 1, x_5 = 1, x_7 = 1, x_8 = 1

  • x3=0,x6=0x_3 = 0, x_6 = 0

Substituting these values:

Maximum value=1+1−0+1+1−0+1+1=6\text{Maximum value} = 1 + 1 - 0 + 1 + 1 - 0 + 1 + 1 = 6

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Trees previous year question is Q39 of the GATE CSE 2014 Set 2 paper. Find more GATE CSE PYQs on Trees in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Trees PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Trees in GATE CSE

Trees has 13 GATE CSE PYQs across 11 papers from 2012 to 2026. This is the only 2-mark NAT question among them, and it is the only one in GATE CSE 2014 Set 2.

How GATE tests Trees

More from GATE CSE 2014 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 2 · Q39 · NAT

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 …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.