@@ -22,6 +22,7 @@ Here is what the module can do:
2222 :meth:`connected_components_sizes` | Return the sizes of the connected components as a list.
2323 :meth:`blocks_and_cut_vertices` | Return the blocks and cut vertices of the graph.
2424 :meth:`blocks_and_cuts_tree` | Return the blocks-and-cuts tree of the graph.
25+ :meth:`biconnected_components` | Return the list of biconnected components.
2526 :meth:`biconnected_components_subgraphs` | Return a list of biconnected components as graph objects.
2627 :meth:`number_of_biconnected_components` | Return the number of biconnected components.
2728 :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):
779780 return g
780781
781782
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+
782820def biconnected_components_subgraphs (G ):
783821 r """
784822 Return a list of biconnected components as graph objects.
785823
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.
788826
789827 INPUT:
790828
@@ -816,7 +854,7 @@ def biconnected_components_subgraphs(G):
816854 if not isinstance (G, GenericGraph):
817855 raise TypeError (" the input must be a Sage graph" )
818856
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() ]
820858
821859
822860def number_of_biconnected_components (G ):
@@ -880,7 +918,7 @@ def number_of_biconnected_components(G):
880918 if not isinstance (G, GenericGraph):
881919 raise TypeError (" the input must be a Sage graph" )
882920
883- return len ([c for c in G.blocks_and_cut_vertices()[ 0 ] if len (c) > 1 ] )
921+ return len (G.biconnected_components() )
884922
885923
886924def is_edge_cut (G , edges ):
0 commit comments