Adjacency Lists as Neighbor Records
An adjacency list stores each vertex with the edges or neighbors that can be reached in one step.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Represent a small directed graph
If A points to B and C, A's list contains both. If C points to A, C's list contains A and B can have an empty list. Distinguish an empty neighbor list from a missing vertex using dictionary lookup.
Decide how undirected edges are recorded
An undirected A–B edge usually appears in both neighbor lists. For a count of physical edges, account for that duplication. Breadth-first search can scan each adjacency entry once while tracking visited vertices.[1]
Decide which rows an edge must update
In a directed graph with A pointing to B and C, the adjacency list of A contains B and C. B does not contain A unless the reverse edge also exists. In an undirected graph represented by symmetric lists, both endpoints normally receive an entry for an edge. See visited states.
Directed adjacency
A: B, C
B: []
C: A
Outdegree(A)=2, indegree(A)=1
Keep declared vertices even when no edge points away
A sink or isolated vertex still belongs to the graph. Omitting its empty row can distort vertex counts or cause traversal to fail when reached. If parallel edges or weights are meaningful, adjacent records need fields that preserve those distinctions.