template<
class GT,
class Distance = Dft_Dist<GT>,
class SA = Dft_Show_Arc<GT>>
class Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
Kruskal's algorithm is recommended for sparse graphs. It works by sorting all arcs by weight and greedily adding arcs that don't form a cycle.
The procedure is parameterized with the following specifications:
- GT: The graph type based on List_Graph.
- Distance<GT>: The arc weight accessor class that must export the following attributes:
- typedef Distance<GT>::Distance_Type: The data type that represents an arc weight.
- Distance<GT>::Distance_Type operator()(typename GT::Arc *a): Returns the weight value of arc a.
- Distance<GT>::Max_Distance: Static constant representing the maximum distance value that an algorithm would consider as infinity.
- typename Distance<GT>::Zero_Distance: Static constant corresponding to the neutral element of addition. Traditionally, in the vast majority of cases, this is zero.
- SA: Arc filter for arc iterators.
Time complexity: O(E log E) where E is the number of arcs. Space complexity: O(V) for the Union-Find structure.
- See also
- Prim_Min_Spanning_Tree
Definition at line 89 of file Kruskal.H.
Paints the minimum spanning tree arcs on the graph.
After calling this method, the arcs belonging to the MST are marked with the Spanning_Tree bit. Use is_painted() to check if the tree has been painted.
- Note
- The const_cast on g is safe because sort_arcs only changes the physical ordering of arcs, not the logical graph structure.
- Parameters
-
| [in] | g | The graph for which to compute the minimum spanning tree. |
- Exceptions
-
| domain_error | If g is a digraph. |
Definition at line 166 of file Kruskal.H.
References ah_domain_error_if, ARC_BITS, Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::arc_is_in_tree(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::dist, Fixed_Relation::get_num_blocks(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), GraphCommon< GT, Node, Arc >::is_digraph(), Fixed_Relation::join(), Aleph::maps(), NODE_COUNTER, Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::painted, GraphCommon< GT, Node, Arc >::reset_bit_arcs(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::sa, and Aleph::Spanning_Tree.
Referenced by Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::operator()(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::operator()(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree().
Paints the MST on g and copies it to a separate tree graph.
First paints the spanning tree arcs on g, then creates a copy of the MST in the tree parameter.
- Parameters
-
| [in] | g | The graph for which to compute the minimum spanning tree. |
| [out] | tree | The graph where the resulting minimum spanning tree will be stored. This graph is cleared before the algorithm starts. |
- Exceptions
-
| bad_alloc | If there is not enough memory to construct the tree. |
| domain_error | If g is a digraph. |
Definition at line 209 of file Kruskal.H.
References Aleph::clear_graph(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), GraphCommon< GT, Node, Arc >::map_arcs(), GraphCommon< GT, Node, Arc >::map_nodes(), Aleph::maps(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), and Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::sa.