GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A stack machine evaluates the sum of 16 distinct variables arranged as a perfectly balanced binary tree of additions (addition is commutative so either operand may go first, but the tree shape is fixed). What is the minimum stack depth required?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 16

Correct answer: A. 5

Equal subtrees both needing k force the parent to need k + 1: leaves 1, level 1 needs 2, then 3, 4, and the root 5 = log₂16 + 1. A depth of 16 would be needed only if all operands were pushed first.

More Computer Organization and Architecture questions

Exams that ask this topic