In this paper we propose an algorithm for generating all the spanning trees in undirected graphs. The algorithm requires O(n + m + τ n) time where the given graph has n vertices, m edges, and τ spanning trees. For outputting all the spanning trees explicitly, this time complexity is optimal.Our algorithm follows a special rooted tree structure on the skeleton graph of the spanning tree polytope. The rule by which the rooted tree structure is traversed is irrelevant to the time complexity. In this sense, our algorithm is flexible.If we employ the depth-first search rule, we can save the memory requirement to O(n + m). A breadth-first implementation requires as much as O(m + τ n) space, but when a parallel computer is available, this might have an advantage. When a given graph is weighted, the best-first search rule provides a ranking algorithm for the minimum spanning tree problem. The ranking algorithm requires O(n + m + τ n) time and O(m + τ n) space when we have a minimum spanning tree.
Introduction.In this paper we propose an algorithm which generates all the spanning trees explicitly in O(n + m + τ n) time where the given graph has n vertices, m edges, and τ spanning trees. For outputting all the spanning trees explicitly, the time complexity is optimal.Our algorithm generates all the spanning trees by following one-dimensional faces of the spanning tree polytope (the convex hull of the characteristic vectors of spanning trees). More precisely, our algorithm traverses a tree structure (a rooted spanning tree) on the skeleton graph of the spanning tree polytope. From the above, our algorithm can be considered as a specialization of the reverse search method proposed by Avis and Fukuda [4], which is a general scheme for solving enumeration problems.Our algorithm has an advantage in that the tree search rule by which we traverse the tree structure on the skeleton graph is irrelevant to the time complexity. Thus, various algorithms with O(n + m + τ n) time complexity can be easily constructed by using different tree search rules. In this sense, our algorithm is flexible. For example, employing the depth-first search rule we obtain an algorithm whose space complexity is O(n + m). A breadth-first implementation requires as much as O(m +τ n) space, but when a parallel computer is available, this might have an advantage. The two tree search rules can even be combined to construct an algorithm which runs parallel but requires a fixed amount of memory storage. When a weighted graph is given, our algorithm generates all the spanning trees in nondecreasing order of weight by employing best-first search rule. The