I am taking the Algorithms, Part I course on coursera and am stuck on a bonus question of the first assignment. I have already submitted my solution and got my marks. This is just for curiosity.
Backwash is appearance of the crossed sites as full (blue) in this image. This happens because I am using virtual top and bottom nodes and connecting the rows below/above them to meet the complexity requirements; so, connecting the top to the bottom makes all the nodes connected to the bottom get connected to the top. This description might appear incomplete so I strongly suggest reading the specs link.
A solution to overcoming this is to use another WeightedQuickUnion object and duplicate the grid in it without including the bottom virtual node. Now, this solution doesn't meet the memory requirements of the grader for the bonus question (check that total memory <= 11 n^2 + 128 n + 1024 bytes). I have thought of some workarounds (like using an array/stack to store the open sites of the bottom row) but all of them use an extra method that has complexity O(n) whereas the assignment doesn't permit that. As per the assignment specs, other than constructor all methods should have a constant time + constant number of calls to union() and find().