Viterbi Algorithm (1967) › The Problem: Finding Needles in Exponential Haystacks

Michael BrenndoerferApril 14, 20253 min read
History of Language AIAll chapters
Part 1 of 9Signals & Symbols
Chapter 8Viterbi Algorithm (1967) › The Problem: Finding Needles in Exponential Haystacks
Reading section 2 of 11 · The Problem: Finding Needles in Exponential Haystacks · 3 minSection 2 of 11 · 3 min

Book contents

Section 2 of 11 · 3 min read

Viterbi Algorithm (1967) › The Problem: Finding Needles in Exponential HaystacksOne section · Sections in this chapter2 / 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 core challenge that motivated the Viterbi algorithm appears whenever you need to determine the most likely hidden sequence from observations. In error-correcting codes, the hidden sequence is the original message bits, and the observations are the noisy received signal. In speech recognition, the hidden sequence is the words or phonemes being spoken, and the observations are acoustic features extracted from audio. In part-of-speech tagging, the hidden sequence is the grammatical categories of words, and the observations are the words themselves.

In each case, the challenge is the same: given an observation sequence of length TT, how do you find the hidden state sequence that most likely produced those observations? If you have NN possible states at each time step, there are NTN^T possible sequences to consider. For even modest values.say, N=50N = 50 states and T=20T = 20 observations.you're dealing with 502050^{20} possible sequences, a number so large that enumerating all possibilities is computationally impossible.

The naive approach would be to compute the probability of each possible sequence given the observations and select the one with the highest probability. But this requires evaluating an exponential number of sequences. Even if each evaluation took only a microsecond, examining all 502050^{20} sequences would take longer than the age of the universe. Clearly, a different approach was needed.

The Structure of Sequential Dependencies

The key insight that makes the Viterbi algorithm possible is the Markov property: the probability of being in a particular state at time tt depends only on the state at time t−1t-1, not on the entire history of states. This means that optimal sequences have optimal prefixes. If the optimal sequence ending at time TT passes through state ii at time tt, then the path from the start to state ii at time tt must also be optimal. Otherwise, you could improve the overall sequence by replacing that suboptimal prefix with an optimal one.

The problem becomes even more challenging when you consider that observations can be ambiguous. In speech recognition, the same acoustic feature might be consistent with multiple different phonemes. In part-of-speech tagging, the word "bank" could be a noun (financial institution) or a verb (to deposit). The system must use context.both the transition probabilities between states and the observation probabilities for each state.to resolve these ambiguities. But doing so requires reasoning about sequences, not just individual decisions.

Before the Viterbi algorithm, researchers attempted various approximations. Some systems made greedy decisions, choosing the most likely state at each time step independently without considering how these choices affected later decisions. This local optimization often led to globally suboptimal sequences. Other systems explored only a subset of possible sequences using heuristics, but couldn't guarantee finding the true optimal solution. What was needed was an algorithm that could efficiently find the globally optimal sequence without exhaustive enumeration.