TY - GEN
T1 - Generating pivot Gray codes for spanning trees of complete graphs in constant amortized time
AU - Liu, Bowie
AU - Wong, Dennis
AU - Lam, Chan Tong
AU - Im, Sio Kei
N1 - Publisher Copyright:
Copyright © 2026 by SIAM.
PY - 2026
Y1 - 2026
N2 - 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(n2) space. In addition, we provide a novel proof of Cayley’s formula, nn−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(n2) time per tree using O(n2) 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(n2) space.
AB - 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(n2) space. In addition, we provide a novel proof of Cayley’s formula, nn−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(n2) time per tree using O(n2) 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(n2) space.
UR - https://www.scopus.com/pages/publications/105033660949
U2 - 10.1137/1.9781611978971.33
DO - 10.1137/1.9781611978971.33
M3 - Conference contribution
AN - SCOPUS:105033660949
T3 - Proceedings of the Annual ACM-SIAM Symposium on Discrete Algorithms
SP - 833
EP - 870
BT - Proceedings of the 2026 Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2026
A2 - Larsen, Kasper Green
A2 - Saha, Barna
PB - Association for Computing Machinery
T2 - 37th Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2026
Y2 - 11 January 2026 through 14 January 2026
ER -