PHPackages                             mgrechanik/kruskal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mgrechanik/kruskal

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mgrechanik/kruskal
==================

The implementation of the Kruskal algorithm to find a minimum spanning tree

1.0.0(2y ago)04BSD-3-ClausePHPPHP ^8.0

Since Mar 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mgrechanik/kruskal)[ Packagist](https://packagist.org/packages/mgrechanik/kruskal)[ RSS](/packages/mgrechanik-kruskal/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Kruskal's algorithm to find a minimum spanning tree
===================================================

[](#kruskals-algorithm-to-find-a-minimum-spanning-tree)

Demo
-----

[](#demo-)

Example of building a minimum spanning tree: [![Example of building a minimum spanning tree with kruskal's algorithm](https://raw.githubusercontent.com/mgrechanik/kruskal/main/docs/kruskal.jpg "Example of building a minimum spanning tree with kruskal's algorithm")](https://raw.githubusercontent.com/mgrechanik/kruskal/main/docs/kruskal.jpg)

Installing
-----------

[](#installing-)

#### Installing through composer::

[](#installing-through-composer)

The preferred way to install this library is through composer.

Either run

```
composer require --prefer-dist mgrechanik/kruskal

```

or add

```
"mgrechanik/kruskal" : "~1.0.0"

```

to the require section of your `composer.json`.

How to use
-----------

[](#how-to-use--)

Run the next code:

```
use mgrechanik\kruskal\Kruskal;

$matrix = [
    [ 0 , 263, 184, 335],
    [263,  0 , 287, 157],
    [184, 287,  0 , 259],
    [335, 157, 259,  0]
];
$kruskal = new Kruskal($matrix);
if ($kruskal->run()) {
    // 1)
    var_dump($kruskal->getMinimumSpanningTree());
    // 2)
    var_dump($kruskal->getDistance());
}
```

We will get:

1. Spanning tree as an array of edges

```
Array
(
    [0] => Array
        (
            [0] => 0
            [1] => 2
        )

    [1] => Array
        (
            [0] => 2
            [1] => 3
        )

    [2] => Array
        (
            [0] => 1
            [1] => 3
        )

)

```

2. Distance of all tree

```
600

```

This code will find the next path:

[![minimum spanning tree](https://raw.githubusercontent.com/mgrechanik/kruskal/main/docs/democode.jpg "minimum spanning tree")](https://raw.githubusercontent.com/mgrechanik/kruskal/main/docs/democode.jpg)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

789d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83919f51df37e9d419895f01a9d4f55ef44c0dc764aec2a57081b6c5e2a3ed8a?d=identicon)[mgrechanik](/maintainers/mgrechanik)

---

Top Contributors

[![mgrechanik](https://avatars.githubusercontent.com/u/5772506?v=4)](https://github.com/mgrechanik "mgrechanik (12 commits)")

---

Tags

graphkruskalkruskal-mstkruskals-algorithmminimum-cost-subgraphminimum-spanning-treemstpath-planningsearch-algorithmphpgraphminimum spanning treekruskalSearch algorithmpath planningminimum weight spanning treeMinimum-cost subgraphmstKruskal algorithm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mgrechanik-kruskal/health.svg)

```
[![Health](https://phpackages.com/badges/mgrechanik-kruskal/health.svg)](https://phpackages.com/packages/mgrechanik-kruskal)
```

###  Alternatives

[graphp/algorithms

Common mathematical graph algorithms implemented in PHP

1402.9M14](/packages/graphp-algorithms)[sdboyer/gliph

A graph library for PHP.

17029.1k1](/packages/sdboyer-gliph)[fab2s/nodalflow

A PHP Nodal WorkFlow

16362.4k1](/packages/fab2s-nodalflow)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)[halfpastfouram/phpchartjs

PHP library for ChartJS

2512.2k](/packages/halfpastfouram-phpchartjs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
