learngraphtheory.org

Guest User

Using app without sign in

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj

Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Bidirectional BFS Visualizer

Two searches that meet in the middle

Finds the shortest path between two vertices by searching from both ends until the searches meet

Time: O(b^(d/2)), worst case O(V + E)
Space: O(V)
Use Case: Point-to-point shortest paths in large unweighted graphs
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Bidirectional BFS

Bidirectional BFS finds the shortest path between two given vertices of an unweighted graph by running two breadth-first searches at once: one forward from the start and one backward from the target. The search stops as soon as the two frontiers meet, so it usually touches far fewer vertices than a single BFS that has to grow all the way from the start to the target.

How it works

Each side keeps its own queue and its own set of reached vertices. Every round expands one full level of the smaller frontier, which keeps the two searches balanced. When a newly reached vertex has already been seen by the other side, the two partial paths join into a complete path; the round is finished before stopping, so the shortest meeting point wins. With branching factor b and distance d, the work drops from about b^d to about 2·b^(d/2), while the worst case stays O(V + E).

Applications

Bidirectional search speeds up point-to-point queries in large networks: degrees of separation in social graphs, word-ladder puzzles, route lookups in road networks and puzzle solvers such as the Rubik's cube, where the state graph is huge but both the start and the goal are known. It is a favourite follow-up question in coding interviews after a plain BFS solution, and the same idea drives the bidirectional Dijkstra used in route planners.

Related algorithms: Breadth-First Search, Dijkstra's Algorithm, A* Search Algorithm, Iterative Deepening DFS (IDDFS)

Interactive Controls

Zoom Controls

49%
Nodes: 12
Edges: 17