• retagged by
959 views

1 Answer

3 3 votes

I read this example somewhere last year. I don't exactly remember from where. Anyway, it goes like this.

Let us consider a family tree of a tree.

As you can see, the upper levels of the tree consists of the ancestors and the next level consists of their descendents and so on.

When to apply DFS?

If you are searching for someone who is one of the younger members of the family, that the probability of that person to be found is at the bottom of the tree. If you apply DFS, you reach the depth faster. BFS will take longer time to reach the last level.

When to apply BFS?

If you are searching for a member who died long ago or is an elder member of the family, BFS will give you good result because that person would be closer to the root of the tree.

So the answer depends on the type of problem you are about to solve.

Position:
Show:

Related questions

46 46 votes
14 14 answers
22.6k
22.6k views
Arjun asked Feb 16, 2024
22,599 views
The number of edges present in the forest generated by the $\text{DFS}$ traversal of an undirected graph $G$ with $100$ vertices is $40$. The number of connected componen...
0 0 votes
1 answers 1 answer
2.0k
2.0k views
rsansiya111 asked Dec 8, 2021
1,973 views
Consider the following strategy to solve the single source shortest path problem with edge weights from source s.1. Replace each edge with weight w by w edges of weight 1...
1 1 vote
2 2 answers
3.4k
3.4k views
Abhishek Kumar 38 asked Jan 4, 2019
3,377 views
Which of the following statement is true?For a directed graph, the absence of back edges in a DFS tree can have cycle.If all edge in a graph have distinct weight then the...
1 1 vote
4 4 answers
5.1k
5.1k views
eyeamgj asked May 10, 2018
5,140 views
In the following graph, discovery time stamps and finishing time stamps of Depth First Search (DFS) are shown as x/yx/y, where x is discovery time stamp and y is finishin...