Edge Lists and Adjacency Matrices
An edge list represents actual connections as records. An adjacency matrix assigns a position to each possible ordered pair of vertices.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Check three vertices
For directed vertices A, B, C with only A to B and B to C, a Boolean matrix has nine entries and two true values. An edge list has two pairs plus whatever representation keeps the full vertex set known. Row and column indices can map labels to matrix positions.
Choose the cost to favor
A matrix can test one pair directly. A sparse neighbor list can avoid scanning an entire row to enumerate only actual outgoing edges.[1]
Compare the exact size units for one graph
With one thousand vertices and three thousand directed edges, a dense adjacency matrix reserves one million cells. An edge list stores three thousand records, with endpoint fields and optional attributes. Cell size and record size differ, so compare bytes before claiming a memory ratio. See collection memory.
Directed edge A→C
Matrix: set cell (A,C), leave (C,A) unset
Edge list: add record (A,C)
A list of all edges alone does not record isolated vertex B
Choose by the question your code asks frequently
A matrix can answer whether a particular edge exists by indexed access after mapping vertex IDs to positions. An edge list naturally scans all edges. An adjacency list can enumerate outgoing neighbors without scanning unrelated edges. Test isolated vertices under every conversion.