# Why BFS is source vertex specific? [closed]

Take a graph $G=(V,E)$ .

As we know both DFS and BFS are graph search algorithms .

But why the algorithm for BFS is designed in such a way that it does not cares about the vertices that are not connected to the source vertex $s$ but DFS takes care about all vertices in $V$.

I mean if $G$ has $l$ connected components and a vertex $s$ is in one of the connected component among $l$ , then if $s$ is the source vertex for BFS , then BFS performs only traversal on the only one connected component (which contains $s$).

If $G$ is input for BFS , it constructs one BFS tree (for component which contains $s$).

But in case of DFS , it constructs a DFS forest with $l$ DFS trees.

Why no BFS forest and it is restricted to a specifc component (containing $s$)? Any reason involved ?

For Bfs algorithm page # 595 and for Dfs algorithm page # 604 from here

## closed as unclear what you're asking by Luke Mathieson, David Richerby, Rick Decker, lPlant, JuhoAug 18 '14 at 13:40

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Could you please explain how DFS is able to jump from a connected component that contains s to another connected component that does not contain s? – wookie919 Aug 16 '14 at 6:58
• @wookie919 because for every vertex in the graph which is not visited DFS calls DFS_visit on that vertex . So, it covers all vertices in a graph . – hanugm Aug 16 '14 at 7:00
• What's preventing you from doing the same with BFS? I think you may have mis-understood the difference between BFS and DFS. There is no mechanism in DFS (in its purest form) to allow it to reach a vertex that can't be reached from the source, unless you modify it so that it can. – wookie919 Aug 16 '14 at 7:06
• @wookie919 Purest form of DFS means ? Is it when DFS is applied on a connected graph ? – hanugm Aug 16 '14 at 7:09
• @wookie919 is right; this is an arbitrary design decision for implementation that has nothing to do whatsoever with the different algorithmic ideas. Also, I'm pretty sure we covered this before but I can't find the older question. – Raphael Aug 16 '14 at 9:38