private void unionHelper(UFNode<T> child, UFNode<T> parent) {
    if (child == parent)
      return;
    UFNode<T> curr = child;
    UFNode<T> temp = curr;
    while (curr != parent && curr != null) {
      temp = curr.parent;
      curr.addParent(parent);
      curr = temp;
    }
  }