For the following undirected graph, list the maximum number of items ever in the queue. Assume that the starting vertex is A.
ACBDEFIJHG
Challenge 2: Iterative BFS
In this chapter, you went over an iterative implementation of breadth-first search. Now write a recursive implementation.
Challenge 3: Disconnected Graph
Add a method to Graph to detect if a graph is disconnected. An example of a disconnected graph is shown below:
OTDNASJV
Me sonb hai bajxe ldux rsehzabpe, u dtafakdx ovwMivlijot tev okgot mi zse Kpext yrozeyur:
var allVertices: [Vertex<Element>] { get }
Xled zduziyzp iz uxgeeyf ukfcaguzyid hj IspoxoztbCebpex oyf OpyimoghqPuqq.
Solutions
Solution to Challenge 1
The maximum number of items ever in the queue is 3.
Solution to Challenge 2
In the breadth-first search chapter, you learned how to implement the algorithm iteratively. Let’s take a look at how you would implement it recursively.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.