update the algorithm 2 for dimension