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

Function NewUnionFind

graph/unionfind.go:25–33  ·  view source on GitHub ↗

Initialise a new union find data structure with s nodes

(s int)

Source from the content-addressed store, hash-verified

23
24// Initialise a new union find data structure with s nodes
25func NewUnionFind(s int) UnionFind {
26 parent := make([]int, s)
27 rank := make([]int, s)
28 for i := 0; i < s; i++ {
29 parent[i] = i
30 rank[i] = 1
31 }
32 return UnionFind{parent, rank}
33}
34
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.

Callers 2

TestUnionFindFunction · 0.85
KruskalMSTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestUnionFindFunction · 0.68