Termination Criteria for Bidirectional Search
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Bidirectional search is a graph search algorithm that finds the shortest path from an initial node to a goal node by simultaneously exploring from both directions: the start node forward and the goal node backward. This technique can significantly reduce the search space and improve efficiency compared to unidirectional algorithms. One of the crucial aspects of implementing bidirectional search is determining proper termination criteria to ensure the shortest path is found.
Basic Concepts
Bidirectional search involves two simultaneous searches:
- Forward Search: Begins at the start node and moves towards the goal node.
- Backward Search: Begins at the goal node and moves towards the start node.
The main challenge is deciding when to terminate the search. Proper termination ensures the path returned is not only found but is also the shortest possible.
Termination Criteria for Bidirectional Search
There are several factors and strategies for terminating a bidirectional search. These criteria are essential to prevent unnecessary exploration once the shortest path is found.
1. Meeting Point
Definition: Terminate when the two search frontiers intersect.
- Details: When nodes in the forward search meet nodes in the backward search, they form a "meeting point." This indicates a potential path from start to goal.
- Example: In a graph with nodes A to Z, if the forward search reaches node M and the backward search also reaches M, then a path from A to Z has been found.
2. Queue Inspection
Definition: Check conditions on the search front (i.e., queues) to determine termination.
- Details: If the total cost of the paths through two meeting nodes is minimum, then search can be terminated.
- Example: Consider a graph where the forward queue (Qf) and backward queue (Qb) have minimal path costs that are less than or equal to any future potential paths. The criterion can be formulated as: if , stop the search.
3. Heuristic Constraints
Definition: Use heuristics to guide the search and apply constraints to terminate based on estimated path costs.
- Details: Informed search strategies like A* can integrate heuristics to evaluate node potential. The search can end when the estimated total costs are equal in both directions.
- Example: If the forward path cost is estimated as C1 using a heuristic function , and the backward path cost is C2 with , the search can end if reaches a minimum.
Advantages and Challenges
Advantages
- Efficiency: Reduces the depth of the search space, making exploration faster.
- Parallelism: Since two searches occur independently, they can often utilize parallel processing.
Challenges
- Synchronization: Requires careful management to ensure frontiers are synchronized correctly.
- Data Structures: Needs efficient data handling to store and query nodes from both fronts effectively.
- Termination Complexity: Determining an optimal termination point can be complex, especially in large or dynamic graphs.
Technical Examples
Suppose we have a grid where each cell represents a node. Our goal is to find the shortest path from the top-left to the bottom-right.
- Forward Queue: Starts exploring from the top-left node.
- Backward Queue: Starts from the bottom-right node.
- Intersection: Both queues may explore to the center of the grid. Termination occurs when an overlapping node, say node X, is reached that provides a path through it with minimal cost.
Table: Key Concepts and Criteria
| Concept/Criteria | Description | Advantages | Example |
| Meeting Point | Ends search at intersecting node | Decreases redundant exploration | Node X reached in both searches |
| Queue Inspection | Uses frontier costs to decide termination | Builds on expanding minimal paths | Cost comparison of Qf and Qb |
| Heuristic Constraints | Ends based on heuristic-driven costs | Guides towards optimal path | A* heuristic with cost constraints |
Additional Considerations
- Memory Management: efficiently handle storage of nodes to avoid excess memory consumption.
- Path Reconstruction: once terminated, reconstruct the shortest path by tracing through the meeting node.
- Dynamic Environments: in situations where the graph may change (e.g., moving obstacles), incorporate reactive adjustments in termination criteria.
Conclusion
The effectiveness of bidirectional search hinges on appropriate termination criteria to ensure that the shortest path is efficiently discovered. By strategically determining when to cease exploration, either through meeting points, queue inspections, or heuristic constraints, bidirectional search can offer a powerful alternative to unidirectional exploration, particularly in large and complex problem spaces. Implementing these strategies requires a nuanced understanding of both the search environment and the computational resources at hand.
Related reading

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.