MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / count

Method count

src/main/java/com/thealgorithms/searches/UnionFind.java:89–98  ·  view source on GitHub ↗

Counts the number of disjoint sets. @return the number of disjoint sets

()

Source from the content-addressed store, hash-verified

87 * @return the number of disjoint sets
88 */
89 public int count() {
90 List<Integer> parents = new ArrayList<>();
91 for (int i = 0; i < p.length; i++) {
92 int root = find(i);
93 if (!parents.contains(root)) {
94 parents.add(root);
95 }
96 }
97 return parents.size();
98 }
99
100 @Override
101 public String toString() {

Callers 15

testInitialStateMethod · 0.45
testUnionOperationMethod · 0.45
testUnionWithRankMethod · 0.45
testNoUnionMethod · 0.45
testUnionSameSetMethod · 0.45
testEdgeCasesMethod · 0.45
countDistinctColorsMethod · 0.45
testStreamMethod · 0.45
testCountEmptyListMethod · 0.45

Calls 4

findMethod · 0.95
sizeMethod · 0.65
containsMethod · 0.45
addMethod · 0.45

Tested by 15

testInitialStateMethod · 0.36
testUnionOperationMethod · 0.36
testUnionWithRankMethod · 0.36
testNoUnionMethod · 0.36
testUnionSameSetMethod · 0.36
testEdgeCasesMethod · 0.36
countDistinctColorsMethod · 0.36
testStreamMethod · 0.36
testCountEmptyListMethod · 0.36