Certainly! Breadth-First Search (BFS) is a fundamental graph traversal algorithm that’s commonly applied to problems involving trees, graphs, and grids. Here’s a list of some classic and commonly encountered BFS problems on LeetCode:
-
Binary Tree Level Order Traversal - Problem 102
- Traverse a binary tree level by level.
-
Binary Tree Zigzag Level Order Traversal - Problem 103
- Traverse a binary tree level by level, alternating the direction at each level.
-
Binary Tree Right Side View - Problem 199
- Get the rightmost node at each level of a binary tree.
-
Minimum Depth of Binary Tree - Problem 111
- Find the shortest path from the root node to a leaf node.
-
Cousins in Binary Tree - Problem 993
- Check if two nodes are at the same depth but have different parents.
-
Shortest Path in Binary Matrix - Problem 1091
- Find the shortest path in a binary matrix using BFS.
-
Word Ladder - Problem 127
- Transform one word into another by changing one letter at a time, finding the minimum transformation steps.
-
Word Ladder II - Problem 126
- Similar to Word Ladder but asks for all shortest transformation sequences.
-
Rotting Oranges - Problem 994
- Simulate the spread of rot among oranges in a grid.
-
Course Schedule - Problem 207
- Determine if you can finish all courses given prerequisites (cycle detection in a directed graph).
-
Number of Islands - Problem 200
- Find the number of connected islands in a grid.
-
Pacific Atlantic Water Flow - Problem 417
- Determine which cells can flow to both the Pacific and Atlantic oceans.
-
Surrounded Regions - Problem 130
- Capture regions in a grid surrounded by a boundary.
-
As Far from Land as Possible - Problem 1162
- Find the water cell with the maximum distance from any land cell.
-
01 Matrix - Problem 542
- For each cell in a matrix, find the distance to the nearest zero.
-
Open the Lock - Problem 752
- Find the minimum number of turns required to unlock a lock given a list of deadends.
-
Sliding Puzzle - Problem 773
- Solve a 2x3 sliding puzzle to match the target configuration.
-
Jump Game III - Problem 1306
- Determine if you can reach a position with a zero in an array by jumping.
-
The Maze - Problem 490
- Check if there’s a path in a grid maze from start to destination.
-
The Maze II - Problem 505
- Find the shortest path in a grid maze.
-
Cut Off Trees for Golf Event - Problem 675
- Find the shortest path to cut trees in a grid with obstacles.
-
Shortest Distance from All Buildings - Problem 317
- Find the minimum distance to build a house accessible to all buildings in a grid.
-
Walls and Gates - Problem 286
- Fill each empty room with the distance to its nearest gate.
-
Graph Valid Tree - Problem 261
- Check if an undirected graph forms a valid tree.
-
Connected Components in an Undirected Graph - Problem 323
- Count the number of connected components in an undirected graph.
-
Clone Graph - Problem 133
- Create a deep copy of a graph.
-
Is Graph Bipartite? - Problem 785
- Determine if a graph can be colored with two colors.
This list provides a range of BFS problems from various categories on LeetCode. Let me know if you’d like more details on any of these problems!