Two-Phase Algorithm.