docs: public static int[] pruneTree(int numnodes, int[] tree, int minDegree) {
      // Compute node degrees
      int[] deg = new int[numnodes];
      for(int i = 0; i < tree.length; i++) {
        deg[tree[i]]++;
      }
      // Count nodes to be retained:
      int keep = 0;
      for(int i = 1; i < tree.length; i += 2) {
        if(deg[tree[i - 1]] >= minDegree && deg[tree[i]] >= minDegree) {
          keep++;
        }
      }
      // Build reduced tree
      int j = 0;
      int[] ret = new int[keep];
      for(int i = 1; i < tree.length; i += 2) {
        if(deg[tree[i - 1]] >= minDegree && deg[tree[i]] >= minDegree) {
          ret[j++] = tree[i - 1];
          ret[j++] = tree[i];
        }
      }
      assert (j == ret.length);
      return ret;
    }