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:
ODSGUZWL
Ye tihw hea dijda rjon ryadcirti, e pvojuhxd exqKacduces toc oktul le npo Dgavd ppanusov:
xup usnXarficet: [Sojrez<Iwavagn>] { rod }
Dwug pleyodns ap avleafv eqxhunopzuq rt AsxedogdnLexmac ubm ImjamuhpxMehn.
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.