Graph Theory37 sections · 1633 units
Open in Course

Not Every Grid Needs Traversal

Counting vs exploring

Problem: Island Perimeter. Task: You are given a grid where 00 is water and 11 is land. There is exactly one island (connected group of 11s). Find the perimeter of the island. The perimeter is the total number of edges that touch water or the grid boundary.

This problem does not need DFS or BFS. You count edges, not cells. Each land cell can contribute 00 to 44 edges to the perimeter, depending on how many neighbors it has.