9.10. Breadth First Search Analysis¶
Before we continue with other graph algorithms let us analyze the run
time performance of the breadth first search algorithm. The first thing
to observe is that the while loop is executed,
at most, one time for each vertex in the graph
Of course doing the breadth first search is only part of the task.
Following the links from the starting node to the goal node is the other
part of the task. The worst case for this would be if the graph was a
single long chain. In this case traversing through all of the vertices
would be
Finally, at least for this problem, there is the time required to build
the initial graph. We leave the analysis of the buildGraph
function
as an exercise for you.