Top 25 Breadth First Search (BFS) Practice Problems
Published in
2 min readJun 1, 2020
A Breadth First Search (BFS) is often used for traversing/searching a tree/graph data structure. The idea is to start at the root (in the case of a tree) or some arbitrary node (in the case of a graph) and explores all its neighbors, followed by the next-level neighbors, and so on.
Consider the following graph which marks the order in which the nodes would be discovered in BFS.
In this post, we have listed out some of the commonly asked interview questions that can be solved using the BFS algorithm:
- Breadth-First Search (BFS)
- Transitive closure of a graph
- Check if a graph is strongly connected or not
- Find root vertex of a graph
- Chess Knight Problem | Find the shortest path from source to destination
- Shortest path in a maze — Lee Algorithm
- Find the shortest safe route in a field with sensors present
- Flood Fill Algorithm
- Count number of islands
- Find the shortest path from source to destination in a matrix that satisfies given constraints
- Find minimum passes required to convert all negative values in a matrix
- Snake and Ladder Problem
- Find the shortest distance of every cell from a landmine inside a maze
- Check if an undirected graph contains a cycle or not
- Find maximum cost path in a graph from a given source to a given destination
- Total paths in a digraph from a given source to a destination having exactly `m` edges
- Least cost path in a digraph from a given source to a destination having exactly `m` edges
- Traverse a given directory using BFS and DFS in Java
- Level order traversal of a binary tree
- Depth-First Search (DFS) vs Breadth-First Search (BFS)
- Bipartite Graph
- Compute the least cost path in a weighted digraph using BFS
- Find the path between given vertices in a directed graph
- Print all nodes of a perfect binary tree in a specific order
- Print right view of a binary tree
- Find the minimum depth of a binary tree
Thanks for reading.