Graph Algorithms
Visualize graph traversal and pathfinding algorithms. Understand how they navigate through networks and find optimal paths.
Breadth-First Search
Breadth-First Search explores a graph level by level, visiting all neighbors of a node before moving to the next level. It guarantees the shortest path in unweighted graphs.
Time: O(V + E)
Space: O(V)
Speed50%
Grid Size10 x 10
Start Node
End Node
Visited Node
Path Node
Wall
How Breadth-First Search Works: BFS explores a graph level by level, starting from a source node and exploring all its neighbors before moving to the next level.
- Start at the source node and mark it as visited
- Add the source node to a queue
- While the queue is not empty:
- Dequeue a node from the front of the queue
- Process the node (e.g., check if it's the target)
- Add all unvisited neighbors to the queue and mark them as visited
BFS guarantees the shortest path in unweighted graphs because it explores all nodes at distance k from the source before exploring any node at distance k+1.