private void isValidHelper(int node,int[] counts){
  IntIterator edges=childEdgeRows(node);
  int ncount=0;
  while (edges.hasNext()) {
    int edge=edges.nextInt();
    ++ncount;
    ++counts[0];
    int c=getAdjacentNode(edge,node);
    isValidHelper(c,counts);
    if (counts[0] > counts[1])     return;
  }
}

private void isValidHelper ( int node , int [ ] counts ) { IntIterator edges = childEdgeRows ( node ) ; int ncount = 0 ; while ( edges . hasNext ( ) ) { int edge = edges . nextInt ( ) ; ++ ncount ; ++ counts [ 0 ] ; int c = getAdjacentNode ( edge , node ) ; isValidHelper ( c , counts ) ; if ( counts [ 0 ] > counts [ 1 ] ) return ; } }
isvalidtree ' s recursive helper method .
