QuickUnion-Algorithm-Solved-in-CSharp-Through-TDD is a project mainly written in C#, it's free.
Solving quick union algorithm from Figure 1.7 of Ch. 1 Algorithms in Java by Robert Sedgewick via series of tests
README
In "Algorithms in Java", by Robert Sedgewick, available on Amazon.com here: http://www.amazon.com/Bundle-Algorithms-Java-Third-Parts/dp/0201775786/
Chapter 1 explores a connectivity algorithm in increasingly complex iterations.
The goal of the connectivity process is as follows:
THIS IS THE SECOND ALGORITHM APPROACH THAT THE CHAPTER PROPOSES: Quick Union Algorithm (the first was "Quick Find" Algorithm).
In the Quick Union algorithm: a) each index (the left connection, and the right connection) are traversed to their roots (see below)* b) finally, the left root index is then assigned to the right root index
public int RootOfTreeFor(int index) { var valueFromIndex = _intArray[index];
// from index, get value, then treat it as index to get a new array value, UNTIL THEY MATCH
while (valueFromIndex != _intArray[valueFromIndex])
{
valueFromIndex = _intArray[valueFromIndex];
}
return valueFromIndex;
}