Skip to content
perl6 implementation of Tarjan algorithm
  1. Other 100.0%
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


A perl6 implementation of Tarjan's algorithm for finding strongly connected components in a directed graph.

More information can be found at's_strongly_connected_components_algorithm.

If there is a cycle, then it will be within a strongly connected component. This implies that the absence of strongly connected components (other than a node with itself) means there are no cycles. It is possible there may be no cycles, but a strongly connected component may still exist (if I have interpreted the theory correctly). I was interested in the absence of cycles.

use Algorithm::Tarjan;

my Algorithm::Tarjan $a .= new();

my %h;
# code to fill %h node->[successor nodes]

say 'There are ' ~ $a.find-cycles() ~ ' cycle(s) in the input graph';

If there is a need for the sets of strongly connected components, they can be retrieved from $a.strongly-connected (an array of node names).

You can’t perform that action at this time.