using the Viterbi algorithm