A generalization of the Viterbi algorithm, termed the "max-sum algorithm" (or "max-product algorithm") can be used to find the most likely assignment of all or some subset of latent variables in a large number of graphical models, e.g. Bayesian networks, Markov random fields and conditional random fields. The latent variables need in general to be connected in a way somewhat similar to an HMM, with a limited number of connections between variables and some type of linear structure among the variables. The general algorithm involves "message passing" and is substantially similar to the belief propagation algorithm (which is the generalization of the forward-backward algorithm).