Viterbi Algorithm (1967) › The Solution: Dynamic Programming Through Time
History of Language AIAll chapters Viterbi Algorithm (1967) › The Solution: Dynamic Programming Through TimeOne section · Sections in this chapter3 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The Viterbi algorithm solves the sequence decoding problem using dynamic programming, a technique that builds up solutions to complex problems by combining solutions to simpler subproblems. Instead of considering all possible sequences simultaneously, the algorithm processes the observations sequentially, maintaining for each state at each time step the probability of the most likely path ending in that state, along with a pointer to the previous state in that optimal path.
Formally, if we let represent the probability of the most likely sequence of states ending in state at time , the algorithm computes these values recursively. To compute , we consider all possible previous states and find which transition maximizes the combined probability:
where is the transition probability from state to state , and is the probability of observing given that we're in state . The algorithm also maintains backpointers that record which previous state achieved this maximum, allowing reconstruction of the optimal sequence once all observations have been processed.
The algorithm begins by initializing for all states using the initial state probabilities and the first observation's emission probabilities. Then it iterates forward through time, computing for all states at each time step. After processing all observations, it finds the state that maximizes and uses the backpointers to trace backwards through time, reconstructing the optimal state sequence.
The key efficiency of the Viterbi algorithm comes from pruning. At each time step, for each state, we keep only the single best path leading to that state. All other paths are discarded because they cannot become optimal later. This pruning reduces the computational complexity from (exponential) to (polynomial). For states and observations, this reduces the computation from to approximately operations.a reduction by a factor of roughly .
The algorithm's correctness relies on the optimal substructure property: if the optimal sequence passes through state at time , then the optimal path from the start to state at time is part of the globally optimal sequence. This means we can safely discard all non-optimal paths to state at time , confident that they cannot contribute to an optimal solution. This property holds because of the Markov assumption.future states depend only on the current state, not on the path taken to reach it.