Skip to content

arnellebalane/union-find

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Union Find

Implementation of the Union-Find data structure for NodeJS.

Installation

$ npm install git+https://git@github.com/arnellebalane/union-find.git

Usage

This package exposes four implementations of the Union-Find data structure.

import {
    QuickFindUF,
    QuickUnionUF,
    WeightedQuickUnionUF,
    PathCompressionUF
} from 'union-find';

Api

  • constructor(size): Initializes a new Union-Find data structure with a given size.
  • union(source, target): Connects a node to another.
  • connected(source, target) (Boolean): Checks whether two nodes are connected.

Example

import { QuickFindUF } from 'union-find';

const uf = new QuickFindUF(10);
uf.union(4, 3);
uf.union(3, 8);
uf.connected(4, 8); // => true
uf.connected(1, 3); // => false

Contributing

# or `npm` if yarn is not available
$ yarn install
$ yarn test

License

MIT License

About

Implementation of the Union-Find data structure for NodeJS

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published