Uf

Union-Find is an algorithm that uses disjointsets with few operations to create:

  • A union of two give elements forming a new set with the two elements
  • finding weather two elements are with in a same set (in graph terminology, connected? or not)
  • rank or depth of the element with in the tree (from the given element to the leaf) or end of the tree

Installation

To install the Uf gem add below to your Gemfile

gem 'uf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uf

Usage

uf = Uf::DisjointSet.new([1, 2, 3, 4, 5])

uf.union(1,2)

uf.connected?(1,2)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.