Each hub keeps a list.
transcript
A parcel is stuck at a hub. Which hubs can it still reach? The hubs are not on a grid.
Here are six hubs. A truck link joins two hubs. The links come as a list of pairs.
To find one hub's neighbours, read every pair. That is slow. Build lists instead.
Each hub keeps a list of its neighbours. This is the adjacency list. Hub zero lists two and four.
A two-way link goes in both lists. Zero is in the list of two. So every link adds two entries.
Take hub two. Its list holds zero and five. No other link needs reading. One lookup gives both neighbours.
Building the lists costs one step per link. Six links give twelve entries. After that, every lookup is instant.
BFS and DFS now use the lists. On a grid, a rule found neighbours. On a graph, the list does.
A graph is a list of neighbours per node. Full breakdown in the lecture.