Table of Contents
Fetching ...

Generating pivot Gray codes for spanning trees of complete graphs in constant amortized time

Bowie Liu, Dennis Wong, Chan-Tong Lam, Sio-Kei Im

TL;DR

The paper resolves Knuth’s open problem by delivering the first pivot Gray code for spanning trees of the complete graph $K_n$, enabling constant amortized generation in $O(n^2)$ space. It achieves this via a novel rooted-tree encoding and a recursive GenS framework that navigates $k$-ary Gray codes and reflectable languages to ensure single pivot changes between consecutive trees. The authors also extend the approach to general graphs, producing edge-exchange Gray codes with $O(n^2)$ time per tree and $O(n^2)$ space, and show optimizations for special graph families, including $K_{m,n}$, fan, and wheel graphs. Additionally, a simpler Cayley-based proof of $n^{n-2}$ is derived from the recursive structure, deepening the combinatorial understanding of spanning-tree counts. Supplementary Python implementations and graph-class-specific extensions are provided in appendices, highlighting practical applicability and future research directions in ranking/unranking and broader graph classes.

Abstract

We present the first known pivot Gray code for spanning trees of complete graphs, listing all spanning trees such that consecutive trees differ by pivoting a single edge around a vertex. This pivot Gray code thus addresses an open problem posed by Knuth in The Art of Computer Programming, Volume 4 (Exercise 101, Section 7.2.1.6, [Knuth, 2011]), rated at a difficulty level of 46 out of 50, and imposes stricter conditions than existing revolving-door or edge-exchange Gray codes for spanning trees of complete graphs. Our recursive algorithm generates each spanning tree in constant amortized time using $O(n^2)$ space. In addition, we provide a novel proof of Cayley's formula, $n^{n-2}$, for the number of spanning trees in a complete graph, derived from our recursive approach. We extend the algorithm to generate edge-exchange Gray codes for general graphs with $n$ vertices, achieving $O(n^2)$ time per tree using $O(n^2)$ space. For specific graph classes, the algorithm can be optimized to generate edge-exchange Gray codes for spanning trees in constant amortized time per tree for complete bipartite graphs, $O(n)$-amortized time per tree for fan graphs, and $O(n)$-amortized time per tree for wheel graphs, all using $O(n^2)$ space.

Generating pivot Gray codes for spanning trees of complete graphs in constant amortized time

TL;DR

The paper resolves Knuth’s open problem by delivering the first pivot Gray code for spanning trees of the complete graph , enabling constant amortized generation in space. It achieves this via a novel rooted-tree encoding and a recursive GenS framework that navigates -ary Gray codes and reflectable languages to ensure single pivot changes between consecutive trees. The authors also extend the approach to general graphs, producing edge-exchange Gray codes with time per tree and space, and show optimizations for special graph families, including , fan, and wheel graphs. Additionally, a simpler Cayley-based proof of is derived from the recursive structure, deepening the combinatorial understanding of spanning-tree counts. Supplementary Python implementations and graph-class-specific extensions are provided in appendices, highlighting practical applicability and future research directions in ranking/unranking and broader graph classes.

Abstract

We present the first known pivot Gray code for spanning trees of complete graphs, listing all spanning trees such that consecutive trees differ by pivoting a single edge around a vertex. This pivot Gray code thus addresses an open problem posed by Knuth in The Art of Computer Programming, Volume 4 (Exercise 101, Section 7.2.1.6, [Knuth, 2011]), rated at a difficulty level of 46 out of 50, and imposes stricter conditions than existing revolving-door or edge-exchange Gray codes for spanning trees of complete graphs. Our recursive algorithm generates each spanning tree in constant amortized time using space. In addition, we provide a novel proof of Cayley's formula, , for the number of spanning trees in a complete graph, derived from our recursive approach. We extend the algorithm to generate edge-exchange Gray codes for general graphs with vertices, achieving time per tree using space. For specific graph classes, the algorithm can be optimized to generate edge-exchange Gray codes for spanning trees in constant amortized time per tree for complete bipartite graphs, -amortized time per tree for fan graphs, and -amortized time per tree for wheel graphs, all using space.
Paper Structure (18 sections, 14 theorems, 11 equations, 18 figures, 6 algorithms)

This paper contains 18 sections, 14 theorems, 11 equations, 18 figures, 6 algorithms.

Key Result

Lemma 2.1

Let $T = (t_1, t_2, \ldots, t_h)$ be the tuple corresponding to a spanning tree of $K_n$ rooted at vertex 1, with $p$ vertices at level $\ell-1$ and $q_{\ell-1}$ vertices across levels 0 to $\ell-1$. To exhaustively generate all spanning trees of $K_n$ rooted at vertex 1 that share the same subtree

Figures (18)

  • Figure 1.1: Complete graphs from $K_1$ to $K_5$.
  • Figure 1.2: The 16 spanning trees of $K_4$.
  • Figure 1.3: Edge-exchange Gray code for spanning trees of $K_5$ by Smith's algorithm (Algorithm S in knuth2011). Only part of the listing is shown.
  • Figure 1.4: Pivot Gray code for spanning trees of $F_4$.
  • Figure 2.1: The spanning tree and rooted tree of $K_6$ that corresponds to the tuple $T = (00100, 1100, 22)$.
  • ...and 13 more figures

Theorems & Definitions (26)

  • Lemma 2.1
  • Proof 1
  • Lemma 2.2
  • Proof 2
  • Theorem 2.3
  • Proof 3
  • Lemma 2.4
  • Proof 4
  • Lemma 2.5
  • Proof 5
  • ...and 16 more