GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 11

GATE CSE 2016 Set 2 Q11

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

GATE 2016 Set 2, Q11 1 mark · NAT
Report issue

Tree Properties & Traversals

Question 11, GATE 2016: BFS starts at the root of a binary tree. Vertex t is at distance 4 from the root and is the nth visited vertex, counting the root first. Find the maximum n.
Tap to enlarge
Answer & solution

Official answer: 31.0 : 31.0

Our answer: 31

BFS visits all shallower levels first. A full binary tree has 1+2+4+8=15 nodes above level4 and at most 16 nodes on level4. Taking t last on that level gives position 31, attained by a perfect tree through level4.

The last possible position at depth d in a binary tree is Σ(k=0 to d)2k=2d+1−1. Nodes at greater depth cannot precede t in BFS. Sparse levels or placing t earlier can only reduce its ordinal, so a full tree and a last-on-level choice attain the bound.

Original paper, page 28 · Answer key