A graph is made of nodes and the edges that join them: cities and roads, pages and links, the cells of a maze and the ways between them. Unlike a tree it has no root and no direction: a node can be reached by more than one way, and the ways can form loops.
graph = {"a": ["b", "c"], "b": ["d"], "c": ["d"], "d": []}stack = ["a"]seen = {"a"}while stack:node = stack.pop()for nxt in graph[node]:if nxt not in seen:seen.add(nxt)stack.append(nxt)
A grid is a graph too, only its adjacency list is not written down: a cell's neighbours are the cells above, below, left and right of it. The bot that follows a wall through a maze is walking a graph.