Kosaraju

com.phasmidsoftware.gryphon.traverse.Kosaraju
object Kosaraju

Computes strongly connected components of a directed graph using the Kosaraju-Sharir algorithm. See Kosaraju, 1962. See Kosaraju's Algorithm. See A Strong ConnectivityLazy Algorithm....

The algorithm makes two passes:

Pass 1 — post-order DFS over the reversed graph, collecting vertices in reverse finish order. Because ListJournal prepends, result.result.map(_._1).toList already yields vertices with the last-finished vertex at the head — exactly the seed order required for pass 2.

Pass 2 — DFS over the original graph, seeding vertices in the order produced by pass 1, with a shared visited set carried across seeds. Each DFS tree in pass 2 is exactly one SCC.

NOTE: intended for directed graphs only. For undirected graphs see ConnectedComponents.

When applied to a Directed Acyclic Graph (DAG), the result is a topologically sorted set of SCCs, each of which holds only one vertex.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Kosaraju.type

Members list

Value members

Concrete methods

def stronglyConnectedComponents[V, E](graph: DirectedGraph[V, E])(using random: Random = ..., tracer: Tracer[V] = ...): SCCResult[V]

Computes the strongly connected components (SCCs) of a directed graph using Kosaraju's algorithm.

Computes the strongly connected components (SCCs) of a directed graph using Kosaraju's algorithm.

Value parameters

graph

The directed graph for which strongly connected components are to be computed.

random

An implicit random number generator, defaulting to Random().

tracer

An implicit tracer for logging and debugging, defaulting to Tracer.silent.

Attributes

Returns

An SCCResult[V] mapping each vertex to its strongly connected component identifier.