166 views
2 2 votes

BFS is performed from the root of a binary tree containing $n$ vertices.

For which type of binary tree can BFS require $\Theta(n)$ extra space in the worst case?

  1. A completely skewed binary tree
     
  2. A complete balanced binary tree
     
  3. A tree having exactly one vertex at every level
     
  4. A path containing all $n$ vertices

1 Answer

1 1 vote

BFS stores vertices that have been discovered but have not yet been processed in a queue.

Therefore, the maximum space used by BFS depends on the maximum width of the tree.

Consider a complete binary tree.

At level $0: 1$ vertex

At level $1: 2$ vertices

At level $2: 4$ vertices

At level $k: 2^k$ vertices

For a complete binary tree containing $n$ vertices, the final full level contains a constant fraction of all vertices.

Thus, at some point the BFS queue can contain $\Theta(n)$ vertices simultaneously. 

Now consider a skewed tree or a path.

There is only a constant number of vertices at each level, so the BFS queue contains only $O(1)$ vertices at a time.


$\therefore$ Answer: B

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
159
159 views
GO Classes asked Aug 14
159 views
Consider the standard BFS algorithm, except for one modification:A vertex is marked as visited only when it is removed from the queue, instead of when it is first inserte...
2 2 votes
1 1 answer
171
171 views
GO Classes asked Aug 14
171 views
Let $T$ be a breadth-first search tree of a undirected graph. Let $(x, y)$ be an edge of $G$ that is not an edge of $T$, then one of $x$ or $y$ is an ancestor of the othe...
2 2 votes
1 1 answer
272
272 views
GO Classes asked Aug 14
272 views
Suppose BFS is run on a cycle graph $C_n$. For which values of $n$ will no coloring conflict occur?All $n$ Odd $n$ Even $n$ Only prime $n$
2 2 votes
1 1 answer
125
125 views