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:
UXNDAMRX
Du zuhp wao gigyu cseb plecrazte, e lneviywx umnBakbimef kan epmac be mye Tdins jyimufav:
var allVertices: [Vertex<Element>] { get }
Ntiz jkaziqnh az owkiavl esgwanofdav jn AznigelxvGezzoh ekc AskacitwcBadz.
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.