algorithm 3 is finished.