Graphs
Tags: #◇Computer Science #◇CCDSALG #◇Graphs #◇Conceptual #◇M6
◇Overview
Graphs consist of a set of vertices (nodes) and a set of edges that connect pairs of distinct vertices. The document differentiates between directed graphs (digraphs) and undirected graphs, noting that digraphs allow self-loops. It explains two primary methods for representing graphs in memory: adjacency lists and adjacency matrices.
◇Important Formulas
Graph Taxonomy & Handshaking Lemmas:
- Undirected Handshaking Lemma:
Corollary: In any undirected graph, the number of vertices with odd degree is always even. - Directed Graph Balance:
- Edge Density Bounds:
- Undirected Simple Graph:
- Directed Graph: (or if self-loops permitted)
Representation Trade-off Matrix:
| Operation | Adjacency Matrix | Adjacency List |
|---|---|---|
| Space Complexity | ||
| Edge Existence Query | ||
| Iterate All Neighbors of | ||
| Add Vertex | (resize matrix) | (amortized) |
| Add Edge | (prepend to list) |
◇Theoretical Framework: Memory Representations
Adjacency List Linked Layout
◇Worked Examples
- Adjacency Matrix Example: For the 4-vertex graph above:
- Dense vs. Sparse Selection: If and (sparse web graph), an Adjacency Matrix requires entries ( MB), while an Adjacency List requires references ( MB). Adjacency lists are strongly preferred for sparse graphs.
◇References & Navigation
- Related Notes: ◇Graphs