Expand description
Hamming graph constructor (ALGO-CN-008).
Counterpart of igraph_hamming() in
references/igraph/src/constructors/regular.c:1070-1153.
The d-dimensional Hamming graph H(n, q) over an alphabet of
size q has q^n vertices indexed by all length-n strings in
{0, 1, …, q-1}^n. Two vertices are connected iff their strings
differ in exactly one position.
The string (x_0, x_1, …, x_{n-1}) maps to vertex id
Σ_i x_i · q^i (little-endian base-q representation), matching
the upstream convention.
Edge count: q^n · (q − 1) · n / 2.
Special cases:
n = 0→ singleton (one vertex), even whenq = 0.n > 0andq = 0→ null graph (zero vertices).q = 1→ singleton (the only string is the all-zero one, no edges).q = 2→ identical to the n-dimensional hypercubeQ_n(seecrate::hypercube).
Algorithm: enumerate every vertex v ∈ [0, q^n); for each digit
position i ∈ [0, n) extract dig = (v / q^i) mod q, then for
every higher digit value dig + j with j ∈ [1, q − dig) emit the
canonical edge (v, v + j · q^i). Because we only walk upward in
each digit, every edge is produced exactly once (lower endpoint
first). Mirrors the upstream C loop.
Time complexity: O(n · q^(n+1)) — for each of the q^n vertices
we iterate n digit positions and emit up to q − 1 outgoing
upward-pointing edges per digit.
Functions§
- hamming
- Build the d-dimensional Hamming graph
H(n, q).