Start by explaining the core idea of bidirectional Dijkstra: run two simultaneous searches from source and target, expanding the node with the smallest tentative distance from either frontier. Then detail the data structures, stopping condition, and how to combine distances to get the shortest path. Finally, discuss complexity, edge cases, and trade-offs compared to standard Dijkstra.
Pro tip: Emphasize that the stopping condition is when the sum of the minimum keys from both priority queues is greater than or equal to the best found meeting distance, not when the frontiers first meet. This subtlety often trips up candidates and shows deep understanding.
Describe how bidirectional Dijkstra runs two Dijkstra searches: one from source (forward) and one from target (backward on reversed edges). Alternate expanding the node with the smallest tentative distance from either search.
For each direction, maintain a priority queue (min-heap) of (distance, node), a distance map, and a predecessor map for path reconstruction. Also keep a variable for the best meeting distance and meeting node.
Stop when the sum of the minimum distances from both priority queues is >= the best meeting distance found so far. When a node is settled in one direction, check if it has been visited in the other; if so, compute the total distance and update the best if smaller.
Once the best meeting node is found, reconstruct the path by following predecessors from the meeting node back to the source in the forward search, and from the meeting node to the target in the backward search (reversing the backward path).
Analyze time and space complexity: O((V+E) log V) time and O(V) space, but with a smaller search space than standard Dijkstra. Discuss edge cases: disconnected graphs (no path), ties in distances, and graphs with zero-weight edges.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.