PHP code example of mgrechanik / kruskal

1. Go to this page and download the library: Download mgrechanik/kruskal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mgrechanik / kruskal example snippets


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());
}