Bidirectional Search is a graph search algorithm used to find the shortest path between a start node and a goal node in an unweighted graph. It performs two simultaneous breadth-first searches, one from the start node towards the goal node and the other from the goal node towards the start node. When the two BFS searches meet in the middle, a shortest path between the start and goal nodes is found.
Algorithm Steps:
Create two empty sets for the forward and backward searches, and two empty queues for the forward and backward frontiers.
Add the start node to the forward set and enqueue it in the forward frontier.
Add the goal node to the backward set and enqueue it in the backward frontier.
While both frontiers are not empty:
a. Perform one step of the forward BFS: Dequeue a node from the forward frontier and explore its neighbors.
b. If the node's neighbors have not been visited by the forward search, add them to the forward set and enqueue them in the forward frontier.
c. Check if any of the forward neighbors have already been visited by the backward search. If so, a path is found, and the algorithm terminates.
d. Perform one step of the backward BFS: Dequeue a node from the backward frontier and explore its neighbors.
e. If the node's neighbors have not been visited by the backward search, add them to the backward set and enqueue them in the backward frontier.
f. Check if any of the backward neighbors have already been visited by the forward search. If so, a path is found, and the algorithm terminates.
If the two searches meet in the middle, construct the shortest path between the start and goal nodes using the common node where they meet.
Bidirectional Search is a graph search algorithm used to find the shortest path between a start node and a goal node in an unweighted graph. It performs two simultaneous breadth-first searches, one from the start node towards the goal node and the other from the goal node towards the start node. When the two BFS searches meet in the middle, a shortest path between the start and goal nodes is found.
Algorithm Steps:
@Kumar-laxmi can you assigned me