New greedy implementation for building a factorTree