bestpath ← the path starting at state bestpathpointer, that follows backpointer[] to states back in time return bestpath, bestpathprob Figure 8 .10 Viterbi algorithm for finding the optimal sequence of tags. Given an observation sequence and an HMM λ = (A, B), the algorithm returns the state path through the HMM that assigns maximum likelihood to the observation sequence.