Graph Representations
Context: FIT1058_MOC Β· symbolic ways to store a Graph in memory Β· edge list, adjacency matrix, adjacency list, incidence matrix Β· trade space against access
Quick Revision
- π― Objective: store a Graph symbolically for algorithms β four standard encodings.
- π¦ Core Components: edge list β adjacency matrix β adjacency list β incidence matrix.
- β‘ Key Constraint: matrix = bits, test; list = compact for sparse graphs.
π Core
1. The Four Representations
- Edge list β set of edges (+ , else isolated vertices vanish).
- Adjacency matrix β bit array, iff ; symmetric, zero diagonal.
- Adjacency list β per vertex, its neighbours (; empty).
- Incidence matrix β bit array, iff vertex is an endpoint; each column has two s.
2. What the Structure Encodes
- Row sum β (Degree and the Handshaking Lemma).
- Total s β .
- βMatrixβ β algebraic operations reveal structure.
βοΈ Core Decision Matrix
| Representation | Space | Adjacency test | Best for |
|---|---|---|---|
| adjacency matrix | dense | ||
| adjacency list | sparse | ||
| edge list | + | scan | compact |
| incidence matrix | β | proofs |
When It Flips: the adjacency matrix is the Binary Relation's matrix over ; row/column sums are degrees, total s . Sparse real graphs favour the list; the incidence matrix is mostly theoretical.
π Exam Execution Trace
Manual Execution Trace
Rows for (order β):
| Step / State | Vertex | Row | Degree |
|---|---|---|---|
| 0 (Init) | β | β | β |
| 1 | 2 | ||
| 2 | 3 | ||
| 3 | 0 |
β οΈ Common Mistakes
- π‘ Edge list needs β isolated vertices () have no edges; matrix is bits regardless, list stores only actual edges.
π§ Active Recall
Describe the adjacency matrix and adjacency list, and when each is preferable.
- Hint: Dense vs sparse.
Answer
- Short answer: Matrix = bits, test, space; list = neighbours per vertex, space.
- Why: Sparse wins list β real graphs store no empty entries.
Why must an edge list include the vertex set, and what does an incidence matrix encode?
- Hint: Isolated vertices; endpoints.
Answer
- Short answer: Edge list omits isolated vertices, so is needed; incidence matrix marks vertex-endpoint pairs (two s per column).
- Why: Theoretical β incidence matrix is used mainly for proofs.