201k views
1 vote
Given two vertices s and t in a connected graph G, which of the two traversals, BFS and DFS can be used to find if there is a path from s to t?

1) BFS
2) DFS
3) Both BFS and DFS
4) None of the above

User Praveen S
by
8.6k points

1 Answer

6 votes

Final answer:

Both BFS and DFS can be used to find if there is a path from s to t in a connected graph G. Hence the correct answer is option 3

Step-by-step explanation:

Both BFS (Breadth First Search) and DFS (Depth First Search) can be used to find if there is a path from s to t in a connected graph G.

In BFS, we start at vertex s and explore all its neighbors before moving to the next level of vertices. If we find the vertex t during the traversal, we can conclude that there is a path from s to t.

In DFS, we explore one branch of the graph as deeply as possible before backtracking. We continue this process until we either find t or reach a dead end. If we find t during the traversal, we can conclude that there is a path from s to t.

Therefore, the correct answer is 3) Both BFS and DFS.

User Anis Jonischkeit
by
7.5k points