Skip to main content

Counting Srtongly Connected Components

Finds the number of strongly connected components (SCC) in a directed graph

Usage

count_strong_connected_components(graph: Graph)

Parameters:
      graph : Graph
            Graph Object

Returns:
      int
            Number of strongly connected components

Example

from jellybeans.algos import count_strong_connected_componentsfrom jellybeans.structures import Graphg = Graph()g.add_vertex(0)g.add_vertex(1)g.add_vertex(2)g.add_vertex(3)g.add_edge(3, 2)g.add_edge(2, 1)g.add_edge(1, 0)res = count_strong_connected_components(g)print(res) # 4