MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Find

Method Find

graph/unionfind.go:37–42  ·  view source on GitHub ↗

Find finds the root of the set to which the given element belongs. It performs path compression to make future Find operations faster.

(q int)

Source from the content-addressed store, hash-verified

35// Find finds the root of the set to which the given element belongs.
36// It performs path compression to make future Find operations faster.
37func (u *UnionFind) Find(q int) int {
38 if q != u.parent[q] {
39 u.parent[q] = u.Find(u.parent[q])
40 }
41 return u.parent[q]
42}
43
44// Union merges the sets, if not already merged, to which the given elements belong.
45// It performs union by rank to keep the tree as flat as possible.

Callers 3

UnionMethod · 0.95
TestUnionFindFunction · 0.95
KruskalMSTFunction · 0.95

Calls

no outgoing calls

Tested by 1

TestUnionFindFunction · 0.76