title: How to efficiently generate all possible spanning trees from a graph
body: <p>First please note that this question is <strong>NOT</strong> asking about <strong>MST</strong>, instead, just <code>all possible spanning trees</code>.</p>
  
  <p>So this is <strong>NOT</strong> the same as <a href="https://stackoverflow.com/questions/4569272/finding-all-minimal-spanning-trees">finding all minimal spanning trees</a> or <a href="https://stackoverflow.com/questions/2935754/all-minimum-spanning-trees-implementation">All minimum spanning trees implementation</a></p>
  
  <hr>
  
  <p>I just need to generate all possible <code>spanning trees</code> from a graph.</p>
  
  <p>I think the brute-force way is straight:</p>
  
  <p>Suppose we have <code>V</code> nodes and <code>E</code> edges.</p>
  
  <ol>
  <li>Get all edges of the graph</li>
  <li>Get all possible combinations of <code>V-1</code> out of <code>E</code> edges.</li>
  <li>Filter out <code>non-spanning-tree</code> out of the combinations (for a spanning tree, all nodes inside one set of <code>V-1</code> edges should appear exactly once)</li>
  </ol>
  
  <p>But I think it is too slow when facing big graph.</p>
  
  <p>Do we have a better way?</p>