BFS & DFS on Graphs and Grids — Complete Guide
Master BFS and DFS on graphs and grids: islands, flood fill, shortest paths, connected components, and multi-source BFS with 5-language implementations.
webcoderspeed.com
6 articles
Master BFS and DFS on graphs and grids: islands, flood fill, shortest paths, connected components, and multi-source BFS with 5-language implementations.
Count connected land components in a binary grid using DFS flood fill or BFS. Classic easy problem, foundation for all island variants.
Find the maximum area of any island in a binary grid. DFS returns the area of each island, track the maximum.
Count islands in grid2 that are subsets of islands in grid1. DFS the island in grid2 and verify every cell is also land in grid1.
Count connected components in an undirected graph given as adjacency matrix. DFS or Union-Find both work.
Count connected components in an undirected graph. Union-Find or BFS both give O(V+E) solution.