UGC-NET Jul 2016 · Trees

MCQ · 2 marks · Problem PROG-DSTR-0047

Suppose you are given a binary tree with n nodes, such that each node has exactly eiter zero or two children. The maximum height of the tree will be
  1. A
    $\frac{n}{2}-1$
  2. B
    $\frac{n}{2}+1$
  3. C
    $(n-1)/2$
  4. D
    $(n+1)/2$

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

Show the worked solutionA tree where every node has 0 or 2 children (full binary tree) with \(n\) nodes has \(i=\frac{n-1}{2}\) internal nodes, since \(n=2i+1\). The height is greatest when the tree is a "caterpillar": each level has one internal node and one leaf, so every internal node lies on the longest path.\[\text{maximum height}=i=\frac{n-1}{2}\ \text{(counting edges).}\]Example: \(n=5\) gives a path of 2 internal nodes and height 2.Answer: C

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