This is the eighteenth lecture in the Probabilistic ML class of Prof. Dr. Philipp Hennig in the Summer Term 2020 at the University of Tübingen. Time-stamped slides available at https://uni-tuebingen.de/en/180804. Contents: * Factor Graphs, again * The Sum-Product Algorithm * The Max-Sum and Max-Product Algorithms * The Junction-Tree Algorithm * Dynamic Programming © Philipp Hennig / University of Tübingen, 2020 CC BY-NC-SA 3.0