Home Statistical Dictionary Viterbi Algorithm

Viterbi Algorithm

A dynamic programming algorithm that finds the single most probable sequence of hidden states in a hidden Markov model, given an observed sequence, rather than the probability of each state considered separately.

Stochastic ProcessesAdvancedFree

In Plain English

The forward-backward algorithm tells you, at every time point, how likely each hidden state was, individually. The Viterbi algorithm answers a related but different question: what's the single best, most coherent complete path through the hidden states, taken as a whole? These can give different answers, the most likely state at each individual time point, stitched together, isn't always the same as the single most likely entire sequence. Viterbi is the workhorse behind decoding speech into words, aligning DNA sequences to genes, and any application where you need one definitive, most-plausible explanation for the whole observed sequence, not just a state-by-state probability estimate.

Definition

Given a hidden Markov model and an observed sequence , the Viterbi algorithm finds , the single hidden state sequence maximizing the joint posterior probability. It uses dynamic programming, defining , the highest joint probability of any path ending in state at time , computed recursively as , while tracking backpointers recording which predecessor state achieved the maximum at each step. After the forward recursion reaches , backtracking through the stored pointers recovers the complete optimal state sequence. Like the forward-backward algorithm, Viterbi runs in time via dynamic programming, replacing sums with maximizations at each step (a substitution known more generally as the max-product, rather than sum-product, algorithm).

Formula

Notation

—Highest joint probability of any path ending in state $i$ at time $t$
—Transition probability from state $i$ to state $j$
—Emission probability of observation $X_t$ given state $j$

Properties

  • The Viterbi algorithm's answer and the forward-backward algorithm's state-by-state most-likely answers can genuinely disagree, stitching together each time point's individually most likely state does not always produce a path that is itself internally consistent under the transition probabilities, only Viterbi's global optimization guarantees the single best whole sequence.
  • Speech recognition systems historically used Viterbi decoding to convert a stream of acoustic observations into the single most likely sequence of phonemes or words, and the same algorithm (often called Viterbi decoding in this context) is separately central to error-correcting convolutional codes in digital communications.
  • In bioinformatics, Viterbi decoding of profile HMMs is a standard technique for gene finding and sequence alignment, identifying the single most likely alignment or annotation of a DNA or protein sequence against a known statistical model of gene structure.

At a Glance

Findsthe single most probable complete hidden state sequence
Contrast with forward-backwardcomputes one best whole path, not per-timepoint marginal probabilities
Mechanismdynamic programming with backpointers, tracking the best predecessor at each step
Efficiency, the same complexity class as the forward-backward algorithm
Last updated September 8, 2026← Back to the Dictionary