Raku Land # Algorithm::Kruskal

github:titsuki # NAME

Algorithm::Kruskal - a perl6 implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length

# SYNOPSIS

``````use Algorithm::Kruskal;

my \$kruskal = Algorithm::Kruskal.new(vertex-size => 4);

my %forest = \$kruskal.compute-minimal-spanning-tree();
%forest<weight>.say; # 3
%forest<edges>.say; # [[1 2] [2 3] [3 0]]
``````

# DESCRIPTION

Algorithm::Kruskal is a perl6 implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length

## CONSTRUCTOR

``````my \$kruskal = Algorithm::Kruskal.new(%options);
``````

### OPTIONS

• `vertex-size => \$vertex-size`

Sets vertex size. The vertices are numbered from `0` to `\$vertex-size - 1`.

## METHODS

### add-edge(Int \$from, Int \$to, Real \$weight)

``````\$kruskal.add-edge(\$from, \$to, \$weight);
``````

Adds a edge to the graph. `\$weight` is the weight between vertex `\$from` and vertex `\$to`.

### compute-minimal-spanning-tree() returns List

``````my %forest = \$kruskal.compute-minimal-spanning-tree();
%forest<edges>.say; # display edges
%forest<weight>.say; # display weight
``````

Computes and returns a minimal spanning tree and its weight.

# AUTHOR

titsuki titsuki@cpan.org