959 views
0 votes
0 votes
BFS algo is applied on graph as well as Binary tree. So, is it different for both graph and Binary tree?

As on youtube some people showing BFS on graph and some on Binary tree.

Kindly clarify, thanks!

1 Answer

Best answer
3 votes
3 votes

One difference between graphs and trees is that graph may contain cycle.

So,when we use  BFS algorithm for  trees there is no problem. //No cycle 

But when we use it for graph we need to check for cycles.   // cycle can be present

For example you can refer link:

http://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/



 

selected by

Related questions

0 votes
0 votes
0 answers
1
saxena0612 asked Dec 8, 2017
338 views
$State \ TRUE \ OR \ FALSE :\\ Given \ an \ undirected \ connected \ graph \ with \ binary \ edge \ weights \ the \\ shortest \ path \ b/w \ any \ two \ nodes \ can \ be ...
0 votes
0 votes
1 answer
2
Subbu. asked Jul 16, 2022
344 views
Please list the problems where BFS alone can do and DFS alone can do and both can do??
1 votes
1 votes
2 answers
3
saptarshiDey asked Feb 1, 2019
857 views
What will be the path from A-H if BFS is used in the following graph?