Which traversal algorithm can be used to find the shortest path betwee...
BFS can be used to find the shortest path between two vertices in an unweighted graph.
View all questions of this test
Which traversal algorithm can be used to find the shortest path betwee...
Breadth First Search (BFS) is the traversal algorithm that can be used to find the shortest path between two vertices in an unweighted graph.
Explanation:
- BFS is a graph traversal algorithm that explores all the vertices of a graph in breadth-first order, i.e., it visits all the vertices at the same level before moving to the next level.
- In the context of finding the shortest path between two vertices in an unweighted graph, BFS can be used because it guarantees that the shortest path will be found.
- BFS uses a queue to keep track of the vertices to be visited. It starts from the source vertex and visits its adjacent vertices. Then, it visits the adjacent vertices of the visited vertices and so on.
- The key idea behind using BFS to find the shortest path is that the shortest path between two vertices is the path with the minimum number of edges. As BFS visits the vertices level by level, it ensures that the path found will be the shortest.
- When BFS visits a vertex, it marks it as visited and enqueues its adjacent vertices. This process continues until the destination vertex is visited or all the vertices have been visited.
- Once the destination vertex is visited, the shortest path can be reconstructed by backtracking from the destination vertex to the source vertex, following the parent pointers that were set during the BFS traversal.
- Since BFS explores all the vertices in breadth-first order, it guarantees that the shortest path will be found if it exists.
- On the other hand, depth-first search (DFS) does not guarantee finding the shortest path as it explores one branch of the graph deeply before backtracking.
Therefore, the correct answer is option 'B' (Breadth First Search (BFS)).