UGC-NET Nov 2017 · Trees

MCQ · 2 marks · Problem PROG-DSTR-0007

Consider a full binary tree with \(n\) internal nodes, internal path length \(i\), and external path length \(e\). The internal path length of a full binary tree is the sum, taken over all internal nodes of the tree, of the depth of each node. Similarly, the external path length is the sum, taken over all leaves of the tree, of the depth of each leaf.Which of the following is correct for the full binary tree?
  1. A
    \(e=i+n\)
  2. B
    \(e=i+2n\)
  3. C
    \(e=2i+n\)
  4. D
    \(e=2^{n}+i\)

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solution\[\boxed{e=i+2n}\]Grow the tree one step at a time by turning a leaf at depth \(d\) into an internal node with two leaf children:\(n\) increases by 1, \(i\) increases by \(d\), and \(e\) changes by \(-d+2(d+1)=d+2\).So \(e-i-2n\) never changes. For the one-node tree, \(n=i=e=0\), so \(e-i-2n=0\) always.Example: a root with two leaves has \(n=1\), \(i=0\), \(e=2=0+2(1)\).Answer: B

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com