GATE / CS ARCHIVE

GATE CSE 2014 SET 2 / QUESTION 39

GATE CSE 2014 Set 2 Q39

Data Structures · Tree Properties & Traversals · Full GATE CSE 2014 Set 2 paper

GATE 2014 Set 2, Q39 2 marks · NAT
Report issue

Tree Properties & Traversals

Question 39, GATE 2014: An expression tree has root +. Its left child is -, with children +(a,b) and -(c,d); its right child is +, with children -(e,f) and +(g,h). Every leaf a,b,c,d,e,f,g,h independently takes value 0 or 1. Find the maximum value of ((a+b)-(c-d))+((e-f)+(g+h)).
Tap to enlarge
Answer & solution

Official answer: 6

1. Set up the reasoning. Expand parentheses carefully, especially the subtraction of (c-d). This turns the tree into a linear expression with independent binary variables.

2. Derive the result. Label leaves left-to-right a,..., h. The expression expands as(a+b)−(c−d)+(e−f)+(g+h)=a+b−c+d+e−f+g+h. Set the six positive-coefficient leaves to 1 and the two negative-coefficient leaves to 0. The maximum is 6.

3. Check the interpretation. The d term is positive because it is subtracted twice. Set positive-coefficient leaves to one and negative-coefficient leaves to zero. The resulting assignment attains the coefficient upper bound, so it proves a maximum rather than only an example value.

Original paper, page 40 · Answer key