Set Partitioning in Hierarchical Trees algorithm implementation