# kruskal-mst

> Implementation of Kruskal's algorithm for finding a minimum spanning forest of an unidirected edge-weighted graph.

Latest version **1.0.0** (published 2021-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install kruskal-mst
pnpm add kruskal-mst
yarn add kruskal-mst
bun add kruskal-mst
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-03-15 |
| First published | 2021-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | D Dranidis |
| Maintainers | dranidis |
| Keywords | Kruskal, Kruskal's algorithm, Minimum spanning forest, Minimum spanning tree |

## Links

- npm: https://www.npmjs.com/package/kruskal-mst
- Repository: https://github.com/dranidis/kruskal-mst
- Homepage: https://github.com/dranidis/kruskal-mst#readme
- Issues: https://github.com/dranidis/kruskal-mst/issues
- npm.io page: https://npm.io/package/kruskal-mst

## Dependencies (1)

- [disjoint-set-ds](https://npm.io/package/disjoint-set-ds.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2021-03-15

## README

[![npm version](https://badge.fury.io/js/kruskal-mst.svg)](https://badge.fury.io/js/kruskal-mst)
[![Build Status](https://travis-ci.com/dranidis/kruskal-mst.svg?branch=main)](https://travis-ci.com/dranidis/kruskal-mst)
[![Coverage Status](https://coveralls.io/repos/github/dranidis/kruskal-mst/badge.svg)](https://coveralls.io/github/dranidis/kruskal-mst)
[![Dependencies Status](https://status.david-dm.org/gh/dranidis/kruskal-mst.svg)](https://status.david-dm.org/gh/dranidis/kruskal-mst)



# kruskal-mst

Kruskal's algorithm finds a minimum spanning forest of an undirected edge-weighted graph. If the graph is connected, it finds a minimum spanning tree.

For more information read: https://en.wikipedia.org/wiki/Kruskal%27s_algorithm

## Usage

### Javascript
```javascript
k = require('kruskal-mst');
edges = [
    { from: 'A', to: 'B', weight: 1 },
    { from: 'A', to: 'C', weight: 5 },
    { from: 'A', to: 'E', weight: 7 },
    { from: 'B', to: 'C', weight: 2 },
    { from: 'B', to: 'D', weight: 5 },
    { from: 'C', to: 'F', weight: 8 },
    { from: 'D', to: 'E', weight: 3 },
    { from: 'D', to: 'F', weight: 4 },
    { from: 'E', to: 'F', weight: 5 },
  ];
  mst = k.kruskal(edges);

  console.log(mst);
```

#### Output:
```javascript
[
  { from: 'A', to: 'B', weight: 1 },
  { from: 'B', to: 'C', weight: 2 },
  { from: 'D', to: 'E', weight: 3 },
  { from: 'D', to: 'F', weight: 4 },
  { from: 'B', to: 'D', weight: 5 }
]
```

### Typescript
```typescript
import { kruskal, Edge } from 'kruskal-mst';

const edges: Edge<string>[] = [
    { from: 'A', to: 'B', weight: 1 },
    { from: 'A', to: 'C', weight: 5 },
    { from: 'A', to: 'E', weight: 7 },
    { from: 'B', to: 'C', weight: 2 },
    { from: 'B', to: 'D', weight: 5 },
    { from: 'C', to: 'F', weight: 8 },
    { from: 'D', to: 'E', weight: 3 },
    { from: 'D', to: 'F', weight: 4 },
    { from: 'E', to: 'F', weight: 5 },
  ];
  const spanningTree = kruskal(edges);

  console.log(spanningTree);
```

---
_Source: https://npm.io/package/kruskal-mst · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
