The GATE Grind

GATE 2016 CS (CS2) – Question 21

Programming and Data Structures · Trees and Binary Search Trees · 1 mark · Numerical answer

BFS starts at the root of a binary tree. A vertex t is at distance four. If t is the n-th vertex visited, find the maximum n.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 31.0 to 31.0

Explanation

At most 1+2+4+8=15 vertices occur before level four. Level four can contain 16 vertices. Put t last on that full level to attain n=15+16=31. BFS cannot visit a deeper level first, so this is maximal.

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →