complete backward algorithm.