retagged by
550 views
2 votes
2 votes
Why DFS is more efficient than BFS in determining the presence of a cycle in graph ?Explain please .
retagged by

1 Answer

1 votes
1 votes
DFS and BFS both detects cycle in directed and undirerected graphs in $O(V+E)$.

The reason for using DFS is that it is easier to implement using stack. With much efficient memory utilization, we can backtrack to find if a node has been visited more than once. Stack will contain the nodes forming cycle. With BFS, each vertex needs to be extracted from the queue if we want to print the cycle.

Related questions

2.2k
views
2 answers
3 votes
suchismith roy asked May 27, 2016
2,178 views
DFS is done for a graph.So we need a visited array to keep track of cycles.Do we need visited array for DFT of a tree?What is the basic difference between traversal and search ?
927
views
2 answers
1 votes
saptarshiDey asked Feb 1, 2019
927 views
What will be the path from A-H if BFS is used in the following graph?
979
views
2 answers
0 votes
srestha asked Jun 30, 2018
979 views
How through a BFS we can find graph is connected or disconnected? Plz give some example and explain
1.4k
views
2 answers
2 votes
sumit chakraborty asked Jan 11, 2018
1,384 views
If DFS algorithm applied starting from vertex ‘A’ which uses stack data structure then the height of stack is needed in worst case for DFS traversal is _________.