Skip to content

Implementation of Weighted Quick Union-Find with Path Compression data structure.

Notifications You must be signed in to change notification settings

juzerali/unionfind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Union Find NPM version

A quick union find data structure for javascript

API

Constructor

var UnionFind = require('unionfind')
var uf = new UnionFind(size[, key])

Initialize the Union Find data structure with number of distinct groups to begin with. Each group will be referred to as index of the array of size size starting at 0. You can also provide an optional key function that maps these indices in a certain way. For example if you would like to refer to the groups starting with 1 provide the function function(a){return a-1;}. The default value is function(a){return a;}.

UnionFind#union

uf.union(p, q);

Combine elements in groups p and q into a single group. In other words connect the two groups.

UnionFind#find

uf.find(p);

Return the root (value) of the group in which p is.

UnionFind#Connected

uf.connected(p, q);

Returns true if p and p are both in same group, false otherwise.

UnionFind#size

uf.size();

Returns the number of elements of uf object.

UnionFind#count

uf.count();

Returns the number of distinct groups left inside the object.

Licence MIT

About

Implementation of Weighted Quick Union-Find with Path Compression data structure.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published