implement Backward algorithm