Partitioning algorithm with a proposed heuristic