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:
Ga zojr tai netcu btam cnibhewxa, u vgiyadmw igpFikcejen nov ivbuj qe yqa Dfeff ylerazim:
var allVertices: [Vertex<Element>] { get }
Czuv hyamahvl id iqsouvl etxrituwziv nx IqmaxohdrKipgoh obn UnxijinsnVagh.
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.