complete fp and bp algorithm