• edited by
24,735 views
73 73 votes
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^{\text{th}}$ vertex in this BFS traversal, then the maximum possible value of $n$ is __________

10 Answers

Best answer
75 75 votes
No of nodes at level $0$(root)  of tree $\Rightarrow  1$

No of nodes at level $1$ of tree $\Rightarrow  2$

No of nodes at level $2$ of tree $\Rightarrow 4$

No of nodes at level $3$ of tree $\Rightarrow 8$

No of nodes at level $4$ of tree $\Rightarrow 16$

Last node in level $4$th is the node we are looking for $\Rightarrow  1+2+4+8+16 \Rightarrow 31$
• edited by
5 5 votes

No of nodes at distance 0(root)  of tree =>1

No of nodes at distance 1 of tree =>2

No of nodes at distance 2 of tree =>4

No of nodes at distance 3 of tree =>8

No of nodes at distance 4 of tree =>16

Last node at distance 4 is the node we are looking for => 1+2+4+8+16 => 31

3 3 votes
BFS can also be used to find the depth of a binary tree.

The depth of node is defined as the number of edges from the root to the node.

They have given that $n^{th}$ vertex is found at depth 4,what is the maximum value of n?

At each depth, we can have maximum of $2^d$ node where d=current depth.

At, d=4, we would have $2^4=16$ nodes and assuming our tree is complete binary tree, The number of node till depth 3 are

$2^0+2^1+2^2+2^3=15$ nodes.

So, if root starts from as node 1, till depth 3, we would have node numbered 15.

At depth 4, we have 16 nodes and they will be numbered till 16+(16-1)=31. i.e. node numbered from 16 to 31.

So, maximum numbered node our BFS can see at depth 4 is 31.

Answer-31
2 2 votes

It will help you to understand the problem

Answer:
Position:
Show:

Related questions

53 53 votes
5 answers 5 answers
19.8k
19.8k views
go_editor asked Sep 26, 2014
19,787 views
Let $G$ be a graph with $n$ vertices and $m$ edges. What is the tightest upper bound on the running time of Depth First Search on $G$, when $G$ is represented as an adjac...
130 130 votes
11 answers 11 answers
33.6k
33.6k views
Akash Kanase asked Feb 12, 2016
33,560 views
In an adjacency list representation of an undirected simple graph $G=(V, E)$, each edge $(u, v)$ has two adjacency list entries: $[v]$ in the adjacency list of $u$, and $...
63 63 votes
5 answers 5 answers
33.4k
33.4k views
go_editor asked Sep 28, 2014
33,407 views
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checkin...
68 68 votes
9 answers 9 answers
19.0k
19.0k views
go_editor asked Sep 28, 2014
19,041 views
Consider the tree arcs of a BFS traversal from a source node $W$ in an unweighted, connected, undirected graph. The tree $T$ formed by the tree arcs is a data structure f...