Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

GATE | GATE-CS-2016 (Set 2) | Question 21

  • Last Updated : 12 Aug, 2021

Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is ________

[This Question was originally a Fill-in-the-blanks Question]

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

(A) 15
(B) 16
(C) 31
(D) 32

Answer: (C)

Explanation: It would be node number 31 for given distance 4.

For example if we consider at distance 2, below highlighted node G can be the farthest node at position 7.

         /    \
        B       C
       / \     / \
      D   E   F   G

Alternative Solution :
t is the n-th vertex in this BFS traversal at distance four from the root. So height of tree is 4.
Max number of nodes = 2^{h+1} − 1 = 2^{5} − 1 = 31
At distance four, last node is 31. option (C).

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :