@@ -22,6 +22,7 @@ Here is what the module can do:
22
22
:meth:`connected_components_sizes` | Return the sizes of the connected components as a list.
23
23
:meth:`blocks_and_cut_vertices` | Return the blocks and cut vertices of the graph.
24
24
:meth:`blocks_and_cuts_tree` | Return the blocks-and-cuts tree of the graph.
25
+ :meth:`biconnected_components` | Return the list of biconnected components.
25
26
:meth:`biconnected_components_subgraphs` | Return a list of biconnected components as graph objects.
26
27
:meth:`number_of_biconnected_components` | Return the number of biconnected components.
27
28
:meth:`is_cut_edge` | Check whether the input edge is a cut-edge or a bridge.
@@ -779,12 +780,49 @@ def blocks_and_cuts_tree(G):
779
780
return g
780
781
781
782
783
+ def biconnected_components (G ):
784
+ r """
785
+ Return the list of biconnected components.
786
+
787
+ A biconnected component is a maximal subgraph on two or more vertices that
788
+ is biconnected, i. e. , removing any vertex does not disconnect it.
789
+
790
+ INPUT:
791
+
792
+ - ``G`` -- the input graph
793
+
794
+ EXAMPLES::
795
+
796
+ sage: from sage. graphs. connectivity import biconnected_components
797
+ sage: G = Graph( {0: [1, 2 ], 1: [0, 2 ], 2: [0, 1, 3 ], 3: [2 ]})
798
+ sage: sorted( len( b) for b in biconnected_components( G))
799
+ [2, 3 ]
800
+ sage: sorted( len( b) for b in biconnected_components( 2 * G))
801
+ [2, 2, 3, 3 ]
802
+
803
+ TESTS:
804
+
805
+ If ``G`` is not a Sage graph, an error is raised::
806
+
807
+ sage: from sage. graphs. connectivity import biconnected_components
808
+ sage: biconnected_components( 'I am not a graph')
809
+ Traceback ( most recent call last) :
810
+ ...
811
+ TypeError: the input must be a Sage graph
812
+ """
813
+ from sage.graphs.generic_graph import GenericGraph
814
+ if not isinstance (G, GenericGraph):
815
+ raise TypeError (" the input must be a Sage graph" )
816
+
817
+ return [b for b in blocks_and_cut_vertices(G)[0 ] if len (b) > 1 ]
818
+
819
+
782
820
def biconnected_components_subgraphs (G ):
783
821
r """
784
822
Return a list of biconnected components as graph objects.
785
823
786
- A biconnected component is a maximal subgraph that is biconnected, i . e . ,
787
- removing any vertex does not disconnect it.
824
+ A biconnected component is a maximal subgraph on two or more vertices that
825
+ is biconnected, i . e . , removing any vertex does not disconnect it.
788
826
789
827
INPUT:
790
828
@@ -816,7 +854,7 @@ def biconnected_components_subgraphs(G):
816
854
if not isinstance (G, GenericGraph):
817
855
raise TypeError (" the input must be a Sage graph" )
818
856
819
- return [G.subgraph(c) for c in blocks_and_cut_vertices(G)[ 0 ] ]
857
+ return [G.subgraph(c) for c in G.biconnected_components() ]
820
858
821
859
822
860
def number_of_biconnected_components (G ):
@@ -880,7 +918,7 @@ def number_of_biconnected_components(G):
880
918
if not isinstance (G, GenericGraph):
881
919
raise TypeError (" the input must be a Sage graph" )
882
920
883
- return len ([c for c in G.blocks_and_cut_vertices()[ 0 ] if len (c) > 1 ] )
921
+ return len (G.biconnected_components() )
884
922
885
923
886
924
def is_edge_cut (G , edges ):
0 commit comments