code: public static TreeMap<Integer, Integer> calculateFanOuts(final FSA fsa, int root) {
      final int[] result = new int[256];
      fsa.visitInPreOrder(new StateVisitor() {
        public boolean accept(int state) {
          int count = 0;
          for (int arc = fsa.getFirstArc(state); arc != 0; arc = fsa.getNextArc(arc)) {
            count++;
          }
          result[count]++;
          return true;
        }
      });
  
      TreeMap<Integer, Integer> output = new TreeMap<Integer, Integer>();
  
      int low = 1; // Omit #0, there is always a single node like that (dummy).
      while (low < result.length && result[low] == 0) {
        low++;
      }
  
      int high = result.length - 1;
      while (high >= 0 && result[high] == 0) {
        high--;
      }
  
      for (int i = low; i <= high; i++) {
        output.put(i, result[i]);
      }
  
      return output;
    }
docs: Calculate fan-out ratio (how many nodes have a given number of outgoing arcs).
  
  @param fsa The automaton to calculate fanout for.
  @param root The starting node for calculations.
  
  @return The returned map contains keys for the number of outgoing arcs and
  an associated value being the number of nodes with that arc number.