Sum-product algorithm and max-sum Algorithm for chains implemented.