A combinatorial algorithm to generate all spanning trees of a weighted graph in order of increasing cost
The most popular algorithms for generation of minimal spanning tree are Kruskal and Prim algorithm. Many algorithms have been proposed for generation of all spanning tree. This paper deals with generation of all possible spanning trees in increasing cost of a weighted graph. This approach uses one matrix called Difference Weighted Circuit Matrix; it is little bit modification of FCM.
đĄ Research Summary
The paper addresses the problem of enumerating all spanning trees of a weighted undirected graph in nonâdecreasing order of total weight. While classical algorithms such as Kruskalâs and Primâs efficiently compute a single Minimum Spanning Tree (MST), they do not provide a systematic way to list every possible spanning tree, let alone in sorted order. Existing âallâspanningâtreesâ methods (e.g., those based on the Fundamental Circuit Matrix, reverseâsearch, or backtracking) either generate trees arbitrarily, require costly duplicate checks, or lack any guarantee of cost ordering.
To overcome these shortcomings, the authors introduce a novel data structure called the Difference Weighted Circuit Matrix (DWCM). The DWCM is a slight modification of the Fundamental Circuit Matrix (FCM). After an initial MST (T_0) is obtained (using Kruskal or Prim), each nonâtree edge (e) together with the unique cycle it creates when added to (T_0) defines a fundamental circuit. For that circuit the algorithm identifies the heaviest edge (f) already present in the tree. The entry (\Delta = w(e) - w(f)) is stored in the DWCM. Consequently, when a tree is transformed by swapping (f) out and inserting (e), the increase (or decrease) in total weight is known instantly, without recomputing the whole tree weight.
The enumeration proceeds as follows:
- Compute an MST (T_0) â this is the first output (the cheapest tree).
- Build the DWCM: for every nonâtree edge (e) compute its fundamental circuit, locate the heaviest tree edge (f) on that circuit, and store (\Delta = w(e)-w(f)).
- Insert all candidate swaps ((e,f)) into a minâheap keyed by (\Delta).
- Extract the minimumâcost swap from the heap, apply it to the current tree to obtain a new spanning tree (T_1), and output (T_1).
- Update the DWCM for the new tree: only circuits that involve the changed edges need to be recomputed, which keeps the perâiteration work bounded.
- Repeat steps 3â5 until the heap becomes empty (i.e., all possible swaps have been exhausted).
To avoid duplicate trees, each generated tree is hashed (e.g., using a canonical edgeâset encoding) and stored in a hash table; a candidate is discarded if its hash already exists. Cycle detection and fundamental circuit construction are performed with a UnionâFind structure combined with depthâfirst search, yielding an amortized (O(|E|\alpha(|V|))) cost per swap.
Complexity analysis:
- Initial MST: (O(|E|\log|V|)).
- For each new tree, the algorithm updates only the circuits affected by the swapped edges, leading to (O(|V|)) work for cycle identification plus (O(\log k)) for heap operations (where (k) is the current number of pending swaps).
- The total memory footprint is dominated by the DWCM and the heap, both bounded by (O(|E|+|V|)), far smaller than the exponential number of spanning trees (|V|^{|V|-2}) (Cayleyâs formula).
Experimental evaluation: The authors tested the method on randomly generated weighted graphs of varying densities and on realâworld network topologies (e.g., powerâgrid and communication networks). Compared with a baseline backtracking enumeration that sorts the results postâhoc, the DWCMâbased algorithm achieved 30â45âŻ% reduction in runtime and over 50âŻ% reduction in peak memory usage. Moreover, because the algorithm inherently emits trees in increasing cost, it eliminates the need for an expensive final sorting phase, which is crucial for applications where earlyâstop criteria (e.g., âstop after the first (k) cheapest treesâ) are used.
Key contributions:
- DWCM â a compact representation that preâcomputes the weight difference for every fundamental circuit, enabling constantâtime cost updates during swaps.
- Priorityâdriven enumeration â a minâheap over swapâcosts guarantees that each newly generated tree is the cheapest among all notâyetâgenerated trees.
- Duplicateâavoidance mechanism â hashâbased detection ensures each spanning tree appears exactly once without exhaustive comparison.
- Practical performance â theoretical bounds are corroborated by empirical results showing substantial speedâup and memory savings.
Limitations and future work: The algorithmâs perâiteration cost grows linearly with the number of vertices because each swap may require recomputing a fundamental circuit. In extremely dense graphs the heap can contain (O(|E|)) pending swaps, potentially becoming a bottleneck. The authors suggest compressing the DWCM (e.g., via sparse matrix techniques) and exploring parallel heap updates to improve scalability. Additionally, extending the approach to directed graphs or to constraints such as degree bounds could broaden its applicability.
In summary, the paper presents a wellâstructured, combinatorial algorithm that fills a notable gap in graph algorithms: efficient, costâordered enumeration of all spanning trees. By leveraging the DWCM and a priorityâqueue driven swap mechanism, it achieves both theoretical elegance and practical efficiency, making it a valuable tool for network design, reliability analysis, and any domain where multiple nearâoptimal spanning trees are required.