Three Way Partitioning Implementation