Algorithms for Multiphase Partitioning