Bidirectional Search (BDS)
Last updated
Last updated
Bidirectional Search (BDS) is an efficient graph traversal algorithm that conducts two simultaneous searches: one starting from the initial state (forward search) and the other from the goal state (backward search). These searches progress until their respective search trees intersect, signaling that a solution path has been found. By effectively replacing a single large search space with two smaller subgraphs, BDS minimizes the computational overhead, making it an attractive option for navigating vast graphs.
BDS is versatile and can utilize search strategies such as Breadth-First Search (BFS), Depth-First Search (DFS), or Depth-Limited Search (DLS), depending on the problem requirements and resource constraints.
Dual Search Process: BDS simultaneously initiates a forward search from the starting node and a backward search from the goal node.
Intersection-Based Termination: The algorithm halts when the two search trees intersect, signifying that a valid path has been found.
Graph Splitting: Instead of exploring the entire graph in one direction, it reduces the search space by effectively dividing it into two smaller subgraphs.
Customizable Search Techniques: Techniques such as BFS and DFS can be employed in either or both directions, depending on the nature of the problem.
Symmetry: BDS assumes that traversal is possible in both forward and backward directions, which may not be suitable for all graph structures.
Complexity
Searches simultaneously from the initial state and the goal state, meeting in the middle. It can significantly reduce time complexity.
Time Complexity: .
Space Complexity: .
Use Case: Finding the shortest path in undirected graphs.
Faster Search: By splitting the problem into two smaller subgraphs, BDS significantly reduces the number of nodes that need to be expanded, leading to quicker results.
Memory Efficiency: Smaller subgraphs require less memory compared to a single expansive search tree.
Scalability: BDS is particularly useful for extremely large graphs where a single-direction search would be computationally prohibitive.
Reduced Node Expansion Costs: In scenarios where expanding nodes is resource-intensive, BDS limits the total number of expansions, optimizing resource usage.
Complex Implementation: Managing two simultaneous search processes and ensuring their intersection is non-trivial, requiring careful implementation.
Predefined Goal State: BDS necessitates prior knowledge of the goal state, which might not always be available in certain problem domains.
Intersection Challenges: Efficiently identifying the intersection between two search trees can be difficult, potentially increasing the algorithm’s runtime.
Symmetry Requirement: The algorithm assumes that traversal is feasible in both forward and backward directions, limiting its applicability in asymmetric graphs.
Bidirectional Search is a powerful and efficient algorithm for traversing large graphs, leveraging the synergy of dual search trees to minimize computational effort. While its implementation complexity and dependency on goal-state knowledge pose challenges, the algorithm’s benefits in speed and memory efficiency make it a compelling choice for solving a variety of graph-based problems.
In the search tree below, the bidirectional search algorithm is applied. This approach splits the graph or tree into two sub-graphs. One search begins from the starting node (node A) and proceeds forward, while the other starts from the goal node (node O) and moves backward.
The algorithm concludes at node H, where the two searches intersect.
Completeness:
Bidirectional search is complete when BFS is used for both forward and backward searches.
Time Complexity:
In an ideal scenario, where the search trees meet in the middle of the search space, the time complexity of BDS is significantly better than a single-directional search.
Space Complexity:
Bidirectional Search requires maintaining two search trees in memory: one for the forward search and another for the backward search.
Optimality:
Bidirectional search is optimal.
Practical Considerations:
While the theoretical complexities make Bidirectional Search appealing, practical factors like the following can affect performance:
The need for efficient data structures to detect intersections between search trees.
Symmetry in the graph for effective backward traversal.
The overhead of managing two concurrent searches.
In summary, Bidirectional Search has a better theoretical complexity than single-directional search in terms of both time and space, particularly for large search depths. However, its practical performance depends heavily on implementation and problem-specific constraints.
In PHP it can be written as a class UninformedSearchGraph
with implementation of a set of graph operations.
Example of Use:
To try this code yourself, install the example files from the official GitHub repository: https://github.com/apphp/ai-with-php-examples
Single-Directional Search: For algorithms like Breadth-First Search (BFS) applied to an unweighted graph, the time complexity is , where:
is the branching factor (average number of child nodes per node).
is the depth of the solution from the root.
Bidirectional Search: By splitting the search into two halves (forward and backward), the depth each search needs to explore is approximately . Thus, the time complexity becomes: This is a significant improvement over , especially for large d, as the exponential term grows much slower.
Single-Directional Search: Space complexity for BFS is , as it needs to store all nodes at the current level before moving to the next.
Bidirectional Search: Each of the two search trees has a space complexity of . Combined, the total space complexity is approximately: