All Your bases Are Belong to Us: Listing All Bases of a Matroid by Greedy Exchanges

Authors Arturo Merino , Torsten Mütze , Aaron Williams

Thumbnail PDF


  • Filesize: 1.93 MB
  • 28 pages

Document Identifiers

Author Details

Arturo Merino
  • Department of Mathematics, TU Berlin, Germany
Torsten Mütze
  • Department of Computer Science, University of Warwick, Coventry, UK
  • Department of Theoretical Computer Science and Mathematical Logic, Charles University, Prague, Czech Republic
Aaron Williams
  • Department of Computer Science, Williams College, Williamstown, MA, UK


The authors would like to thank the anonymous referees who contributed significantly to the quality of this paper.

Cite AsGet BibTex

Arturo Merino, Torsten Mütze, and Aaron Williams. All Your bases Are Belong to Us: Listing All Bases of a Matroid by Greedy Exchanges. In 11th International Conference on Fun with Algorithms (FUN 2022). Leibniz International Proceedings in Informatics (LIPIcs), Volume 226, pp. 22:1-22:28, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2022)


You provide us with a matroid and an initial base. We say that a subset of the bases "belongs to us" if we can visit each one via a sequence of base exchanges starting from the initial base. It is well-known that "All your base are belong to us". We refine this classic result by showing that it can be done by a simple greedy algorithm. For example, the spanning trees of a graph can be generated by edge exchanges using the following greedy rule: Minimize the larger label of an edge that enters or exits the current spanning tree and which creates a spanning tree that is new (i.e., hasn't been visited already). Amazingly, this works for any graph, for any labeling of its edges, for any initial spanning tree, and regardless of how you choose the edge with the smaller label in each exchange. Furthermore, by maintaining a small amount of information, we can generate each successive spanning tree without storing the previous trees. In general, for any matroid, we can greedily compute a listing of all its bases matroid such that consecutive bases differ by a base exchange. Our base exchange Gray codes apply a prefix-exchange on a prefix-minor of the matroid, and we can generate these orders using "history-free" iterative algorithms. More specifically, we store O(m) bits of data, and use O(m) time per base assuming O(1) time independence and coindependence oracles. Our work generalizes and extends a number of previous results. For example, the bases of the uniform matroid are combinations, and they belong to us using homogeneous transpositions via an Eades-McKay style order. Similarly, the spanning trees of fan graphs belong to us via face pivot Gray codes, which extends recent results of Cameron, Grubb, and Sawada [Pivot Gray Codes for the Spanning Trees of a Graph ft. the Fan, COCOON 2021].

Subject Classification

ACM Subject Classification
  • Theory of computation → Design and analysis of algorithms
  • Mathematics of computing → Combinatorics
  • Mathematics of computing → Combinatorial algorithms
  • Matroids
  • base exchange
  • Gray codes
  • combinatorial generation
  • greedy algorithms
  • spanning trees


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. B. Alspach and G. Liu. Paths and cycles in matroid base graphs. Graphs Combin., 5(3):207-211, 1989. Google Scholar
  2. Bad_CRC. all yor base r blong 2 us., 2001.
  3. Ben Cameron, Aaron Grubb, and Joe Sawada. A pivot gray code listing for the spanning trees of the fan graph. In International Computing and Combinatorics Conference, pages 49-60. Springer, 2021. Google Scholar
  4. Jean Cardinal, Arturo Merino, and Torsten Mütze. Efficient generation of elimination trees and hamilton paths on graph associahedra. In Proceedings of the Thirty-third ACM-SIAM Symposium on Discrete Algorithms (SODA 2022). SIAM, Philadelphia, PA, 2022. Google Scholar
  5. The Combinatorial Object Server: URL:
  6. P. Eades and B. McKay. An algorithm for generating subsets of fixed size with a strong minimal change property. Inform. Process. Lett., 19(3):131-133, 1984. Google Scholar
  7. Jack Edmonds. Matroids and the greedy algorithm. Mathematical programming, 1(1):127-136, 1971. Google Scholar
  8. Fandom contributors. CATS - Villains Fandom., 2022.
  9. Frank Gray. Pulse code communication, 1953. Google Scholar
  10. E. Hartung, H. P. Hoang, T. Mütze, and A. Williams. Combinatorial generation via permutation languages. In Proceedings of the Fourteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 1214-1225. SIAM, 2020. Google Scholar
  11. E. Hartung, H. P. Hoang, T. Mütze, and A. Williams. Combinatorial generation via permutation languages. I. Fundamentals. Transactions of the American Mathematical Society, 2022. Google Scholar
  12. Hung P. Hoang and Torsten Mütze. Combinatorial generation via permutation languages. II. Lattice congruences. Israel J. Math., 244:359-417, 2021. Google Scholar
  13. C. A. Holzmann and F. Harary. On the tree graph of a matroid. SIAM J. Appl. Math., 22:187-193, 1972. Google Scholar
  14. Know your meme contributors. All your base are belong to us - Know your meme., 2022.
  15. D. E. Knuth. The art of computer programming. Vol. 4A. Combinatorial algorithms. Part 1. Addison-Wesley, Upper Saddle River, NJ, 2011. Google Scholar
  16. Yue Li and Joe Sawada. Gray codes for reflectable languages. Inf. Proc. Letters, 109(5):296-300, 2009. Google Scholar
  17. Mandelin, Clyde. How Zero Wing’s "all your base" translation compares with the Japanese script., 2014.
  18. Stephen B. Maurer. Matroid basis graphs. I. J. Comb. Theory Ser. B, 14:216-240, 1973. Google Scholar
  19. Stephen B. Maurer. Matroid basis graphs. II. J. Comb. Theory Ser. B, 15:121-145, 1973. Google Scholar
  20. Arturo I. Merino and Torsten Mütze. Efficient generation of rectangulations via permutation languages. In Proceedings of the 37th International Symposium on Computational Geometry (SoCG 2021), Buffalo, NY, USA, June 7-11 (Virtual Conference), volume 189 of LIPIcs, pages Art. No. 54, 18 pp. Schloss Dagstuhl. Leibniz-Zent. Inform., Wadern, 2021. Google Scholar
  21. Torsten Mütze. Combinatorial Gray codes - an updated survey. arXiv preprint 2202.01280, 2022. Google Scholar
  22. D. J. Naddef and W. R. Pulleyblank. Hamiltonicity and combinatorial polyhedra. J. Combin. Theory Ser. B, 31(3):297-312, 1981. Google Scholar
  23. J. G. Oxley. Matroid theory, volume 3. Oxford University Press, USA, 2006. Google Scholar
  24. Frank Ruskey, Joe Sawada, and Aaron Williams. Binary bubble languages and cool-lex order. J. Comb. Theory, Series A, 119(1):155-169, 2012. Google Scholar
  25. Frank Ruskey and Aaron Williams. The coolest way to generate combinations. Discrete Mathematics, 309(17):5305-5320, 2009. Google Scholar
  26. Ahmad Sabri. Gray codes and efficient exhaustive generation for several classes of restricted words. PhD thesis, Université de Bourgogne, 2015. Google Scholar
  27. J. Sawada, A. Williams, and D. Wong. Inside the binary reflected gray code: Flip-swap languages in 2-gray code order. In International Conference on Combinatorics on Words, pages 172-184. Springer, 2021. Google Scholar
  28. Joe Sawada and Aaron Williams. A universal cycle for strings with fixed-content (which are also known as multiset permutations). In Workshop on Algorithms and Data Structures, pages 599-612. Springer, 2021. Google Scholar
  29. Malcolm J. Smith. Generating spanning trees. Master’s thesis, University of Victoria, 1997. Google Scholar
  30. Brett Stevens and Aaron Williams. The coolest order of binary strings. In International Conference on Fun with Algorithms, pages 322-333. Springer, 2012. Google Scholar
  31. Brett Stevens and Aaron Williams. The coolest way to generate binary strings. Theory of Computing Systems, 54(4):551-577, 2014. Google Scholar
  32. Tadao Takaoka. O (1) time algorithms for combinatorial generation by tree traversal. The Computer Journal, 42(5):400-408, 1999. Google Scholar
  33. D. T. Tang and C. N. Liu. Distance-2 cyclic chaining of constant-weight codes. IEEE Trans. Computers, C-22:176-180, 1973. Google Scholar
  34. Robert E. Tarjan. Efficiency of a good but not linear set union algorithm. Journal of the ACM (JACM), 22(2):215-225, 1975. Google Scholar
  35. M. Thorup. Near-optimal fully-dynamic graph connectivity. In Proceedings of the Thirty-Second Annual ACM Symposium on Theory of Computing, STOC '00, pages 343-350, New York, NY, USA, 2000. Association for Computing Machinery. Google Scholar
  36. Takeaki Uno. A new approach for speeding up enumeration algorithms and its application for matroid bases. In Computing and combinatorics (Tokyo, 1999), volume 1627 of Lecture Notes in Comput. Sci., pages 349-359. Springer, Berlin, 1999. Google Scholar
  37. Vincent Vajnovszki. Gray code order for Lyndon words. Discrete Math. Theor. Comput. Sci., 9(2):145-151, 2007. Google Scholar
  38. Vincent Vajnovszki and Rémi Vernay. Restricted compositions and permutations: from old to new gray codes. Information Processing Letters, 111(13):650-655, 2011. Google Scholar
  39. P. Vámos. On the representation of independence structures. Unpublished manuscript., 1968. Google Scholar
  40. Hassler Whitney. On the abstract properties of linear dependence. Amer. J. Math., 57(3):509-533, 1935. Google Scholar
  41. Wikipedia contributors. All your base are belong to us - Wikipedia, the free encyclopedia., 2022.
  42. Wikipedia contributors. Zero wing - Wikipedia, the free encyclopedia., 2022.
  43. Aaron Williams. Loopless generation of multiset permutations using a constant number of variables by prefix shifts. In Proceedings of the Twentieth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 987-996. SIAM, 2009. Google Scholar
  44. Aaron Williams. The greedy Gray code algorithm. In Algorithms and data structures, volume 8037 of Lecture Notes in Comput. Sci., pages 525-536. Springer, Heidelberg, 2013. Google Scholar
  45. Aaron M. Williams. Shift Gray codes. PhD thesis, University of Victoria, 2009. Google Scholar