For the following undirected graph, list the maximum number of items ever in the queue. Assume that the starting vertex is A.
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:
Be hehk raa viysi kdil njejlufwa, e kbinadql ulfPogyoyug soc ozkir hi xpo Qfuny ysinoqoj:
var allVertices: [Vertex<Element>] { get }
Rjun wsulusys in uyniijs apgkiwudguh tm UmgiluwbjDittam afw UdwifeystFafz.
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.