Nodes and edges: explore outward from a start with a queue (breadth first) or a stack (depth first), stamping each node so you never loop.
▼Transcript
Welcome to the Graphs world. A graph is things and the links between them: stations joined by lines. Each station is a node; each line is an edge.
Here's the move: pick a start, and explore. Breadth first search keeps a queue. It visits every neighbor of the start, then their neighbors, ring by ring. So it reaches each station in the fewest stops.
Depth first search keeps a stack, or uses recursion. It dives down one line as far as it can. At a dead end, it backs up and tries the next branch.
Either way, stamp each station when you first reach it. Graphs have loops: without stamps, you'd ride in circles forever. With them, a visited station is skipped.
The clue: the problem says connected, neighbors, network, path, or prerequisites. And a grid is a graph too: each cell's neighbors are up, down, left and right.
Each station is stamped once, and each line is checked from both ends: O of V plus E time. The stamps take O of V space.
Now let's use it on Number of Islands.