union_find

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DisjointSet

type DisjointSet struct {
	// contains filtered or unexported fields
}

func NewDisjointSet

func NewDisjointSet(n int) *DisjointSet

NewDisjointSet returns an object representing a unordered_set containing n element.

func (*DisjointSet) Find

func (this *DisjointSet) Find(x int) int

Find returns the root of the tree that contains x. Complexity - O(α(n)), where α is the inverse Ackermann function.

func (*DisjointSet) Len

func (this *DisjointSet) Len() int

Len returns the size of the disjoint unordered_set. Complexity - O(1).

func (*DisjointSet) Union

func (this *DisjointSet) Union(x, y int) bool

Union merges the sets represented by x node and the y node into a single unordered_set. Returns whether or not the nodes were disjoint before the union operation (i.e. if the operation had an effect). Complexity - O(α(n)), where α is the inverse Ackermann function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL