An efficient heuristic for partitioning graphs