Table of Contents
Which approach is better DFS or BFS Why?
BFS is better when target is closer to Source. DFS is better when target is far from source. As BFS considers all neighbour so it is not suitable for decision tree used in puzzle games. DFS is more suitable for decision tree.
Which one of the following traversal is best suitable for crawlers for building indexes?
3) Crawlers in Search Engines: Crawlers build index using Breadth First. The idea is to start from source page and follow all links from source and keep doing same. Depth First Traversal can also be used for crawlers, but the advantage with Breadth First Traversal is, depth or levels of the built tree can be limited.
Which of the following is the advantage of DFS over BFS?
The BFS would eventually find the element. If the size of the graph is finite, DFS would likely find a outlier (larger distance between root and goal) element faster where BFS would find a closer element faster.
What is the time complexity of a DFS traversal?
The time complexity of both DFS and BFS traversal is O(V + E), where Vand Eare the total number of vertices and edges in the graph, respectively. Please note that Emay vary between O(1)and O(V2), depending on how dense the graph is.
What is the difference between BFS and DFS with example?
Example: In Web Crawler uses BFS to limit searching the web based on levels. In almost every other case DFS is a great choice. DFS is also easier to implement as explicit usage of data structures can be avoided by recursive implementations.
What is breadth first search (DFS)?
Some applications of Breadth First Search (DFS): The only lucid criteria for using BFS over DFS is when the path length (or level) used to explore a node has a significance. Example: In Web Crawler uses BFS to limit searching the web based on levels.
What is the strategy used by BFS?
The strategy used by BFS is to explore the graph level by level starting from a distinguished source node. Each level consists of a set of nodes which are equidistant from the source node. From a level L, all the unvisited nodes which are direct neighbours of the nodes in L are considered to be the next level, that is L+1.